{"action":"created","comment":{"url":"https://api.github.com/repos/puppetlabs/puppet/pulls/comments/72945905","id":72945905,"diff_hunk":"@@ -0,0 +1,70 @@\n+require 'puppet/generate/util/helpers'\n+\n+module Puppet\n+  module Generate\n+    module Models\n+      module Type\n+        # A model for resource type properties and parameters.\n+        class Property\n+          # Gets the name of the property as a Puppet string literal.\n+          attr_reader :name\n+\n+          # Gets the Puppet type of the property.\n+          attr_reader :type\n+\n+          # Gets the doc string of the property.\n+          attr_reader :doc\n+\n+          # Initializes a property model.\n+          # @param property [Puppet::Property] The Puppet property to model.\n+          # @return [void]\n+          def initialize(property)\n+            @name = Util::to_puppet_string(property.name.to_s)\n+            @type = self.class.get_puppet_type(property)\n+            @doc = property.doc.strip\n+            @is_namevar = property.isnamevar?\n+          end\n+\n+          # Determines if this property is a namevar.\n+          # @return [Boolean] Returns true if the property is a namevar or false if not.\n+          def is_namevar?\n+            @is_namevar\n+          end\n+\n+          # Gets the Puppet type for a property.\n+          # @param property [Puppet::Property] The Puppet property to get the Puppet type for.\n+          # @return [String] Returns the string representing the Puppet type.\n+          def self.get_puppet_type(property)\n+            # HACK: the value collection does not expose the underlying value information at all\n+            #       thus this horribleness to get the underlying values hash\n+            regexes = []\n+            strings = []\n+            values = property.value_collection.instance_variable_get('@values') || {}\n+            values.each do |_, value|\n+              if value.regex?\n+                regexes << \"/#{value.name.source.gsub(/\\//, '\\/')}/\"\n+                next\n+              end\n+\n+              strings << Util::to_puppet_string(value.name.to_s)\n+              value.aliases.each do |a|\n+                strings << Util::to_puppet_string(a.to_s)\n+              end\n+            end\n+\n+            # If no string or regexes, default to Any type\n+            return 'Any' if strings.empty? && regexes.empty?\n+\n+            # Calculate a variant of supported values\n+            enum = \"Enum[#{strings.join(', ')}]\" unless strings.empty?\n+            pattern = \"Pattern[#{regexes.join(', ')}]\" unless regexes.empty?","path":"lib/puppet/generate/models/type/property.rb","position":null,"original_position":60,"commit_id":"72deb23c2a3af5cc8cbf393c3fc222767e0fd555","original_commit_id":"3972229fca9709b4805dd1f2781308467029bced","user":{"login":"thallgren","id":209495,"avatar_url":"https://avatars.githubusercontent.com/u/209495?v=3","gravatar_id":"","url":"https://api.github.com/users/thallgren","html_url":"https://github.com/thallgren","followers_url":"https://api.github.com/users/thallgren/followers","following_url":"https://api.github.com/users/thallgren/following{/other_user}","gists_url":"https://api.github.com/users/thallgren/gists{/gist_id}","starred_url":"https://api.github.com/users/thallgren/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/thallgren/subscriptions","organizations_url":"https://api.github.com/users/thallgren/orgs","repos_url":"https://api.github.com/users/thallgren/repos","events_url":"https://api.github.com/users/thallgren/events{/privacy}","received_events_url":"https://api.github.com/users/thallgren/received_events","type":"User","site_admin":false},"body":"This is nit picking, but the `enum` and `pattern` variables are uninitialized here when their corresponding collections are empty. While uninitialized and `nil` is the same, I still think it's prudent to explicitly initialize to nil, i.e.\r\n```\r\nenum = strings.empty? ? nil : \"Enum[#{strings.join(', ')}]\"\r\n```\r\nThe reason I think this is important is readability (reader don't need to scan the code above to verify that `enum` doesn't retain some other value in case strings is empty).","created_at":"2016-08-01T09:12:52Z","updated_at":"2016-08-01T09:12:53Z","html_url":"https://github.com/puppetlabs/puppet/pull/5161#discussion_r72945905","pull_request_url":"https://api.github.com/repos/puppetlabs/puppet/pulls/5161","_links":{"self":{"href":"https://api.github.com/repos/puppetlabs/puppet/pulls/comments/72945905"},"html":{"href":"https://github.com/puppetlabs/puppet/pull/5161#discussion_r72945905"},"pull_request":{"href":"https://api.github.com/repos/puppetlabs/puppet/pulls/5161"}}},"pull_request":{"url":"https://api.github.com/repos/puppetlabs/puppet/pulls/5161","id":79492486,"html_url":"https://github.com/puppetlabs/puppet/pull/5161","diff_url":"https://github.com/puppetlabs/puppet/pull/5161.diff","patch_url":"https://github.com/puppetlabs/puppet/pull/5161.patch","issue_url":"https://api.github.com/repos/puppetlabs/puppet/issues/5161","number":5161,"state":"open","locked":false,"title":"(PUP-5948) Add code generator for resource types","user":{"login":"hlindberg","id":563066,"avatar_url":"https://avatars.githubusercontent.com/u/563066?v=3","gravatar_id":"","url":"https://api.github.com/users/hlindberg","html_url":"https://github.com/hlindberg","followers_url":"https://api.github.com/users/hlindberg/followers","following_url":"https://api.github.com/users/hlindberg/following{/other_user}","gists_url":"https://api.github.com/users/hlindberg/gists{/gist_id}","starred_url":"https://api.github.com/users/hlindberg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hlindberg/subscriptions","organizations_url":"https://api.github.com/users/hlindberg/orgs","repos_url":"https://api.github.com/users/hlindberg/repos","events_url":"https://api.github.com/users/hlindberg/events{/privacy}","received_events_url":"https://api.github.com/users/hlindberg/received_events","type":"User","site_admin":false},"body":"This adds the \"generate\" face based application to puppet (written by @peterhuene). This PR also contains the integration work (changes to generator and the implementation for which the generator generates code), as well as a number of unit and integration tests.","created_at":"2016-07-31T18:45:20Z","updated_at":"2016-08-01T09:12:53Z","closed_at":null,"merged_at":null,"merge_commit_sha":"b029a36c16ea86eb8defaa7def4feaf659084c59","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/puppetlabs/puppet/pulls/5161/commits","review_comments_url":"https://api.github.com/repos/puppetlabs/puppet/pulls/5161/comments","review_comment_url":"https://api.github.com/repos/puppetlabs/puppet/pulls/comments{/number}","comments_url":"https://api.github.com/repos/puppetlabs/puppet/issues/5161/comments","statuses_url":"https://api.github.com/repos/puppetlabs/puppet/statuses/72deb23c2a3af5cc8cbf393c3fc222767e0fd555","head":{"label":"hlindberg:PUP-5948_add-code-generator-for-resource-types","ref":"PUP-5948_add-code-generator-for-resource-types","sha":"72deb23c2a3af5cc8cbf393c3fc222767e0fd555","user":{"login":"hlindberg","id":563066,"avatar_url":"https://avatars.githubusercontent.com/u/563066?v=3","gravatar_id":"","url":"https://api.github.com/users/hlindberg","html_url":"https://github.com/hlindberg","followers_url":"https://api.github.com/users/hlindberg/followers","following_url":"https://api.github.com/users/hlindberg/following{/other_user}","gists_url":"https://api.github.com/users/hlindberg/gists{/gist_id}","starred_url":"https://api.github.com/users/hlindberg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hlindberg/subscriptions","organizations_url":"https://api.github.com/users/hlindberg/orgs","repos_url":"https://api.github.com/users/hlindberg/repos","events_url":"https://api.github.com/users/hlindberg/events{/privacy}","received_events_url":"https://api.github.com/users/hlindberg/received_events","type":"User","site_admin":false},"repo":{"id":5693635,"name":"puppet","full_name":"hlindberg/puppet","owner":{"login":"hlindberg","id":563066,"avatar_url":"https://avatars.githubusercontent.com/u/563066?v=3","gravatar_id":"","url":"https://api.github.com/users/hlindberg","html_url":"https://github.com/hlindberg","followers_url":"https://api.github.com/users/hlindberg/followers","following_url":"https://api.github.com/users/hlindberg/following{/other_user}","gists_url":"https://api.github.com/users/hlindberg/gists{/gist_id}","starred_url":"https://api.github.com/users/hlindberg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hlindberg/subscriptions","organizations_url":"https://api.github.com/users/hlindberg/orgs","repos_url":"https://api.github.com/users/hlindberg/repos","events_url":"https://api.github.com/users/hlindberg/events{/privacy}","received_events_url":"https://api.github.com/users/hlindberg/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/hlindberg/puppet","description":"Server automation framework and application","fork":true,"url":"https://api.github.com/repos/hlindberg/puppet","forks_url":"https://api.github.com/repos/hlindberg/puppet/forks","keys_url":"https://api.github.com/repos/hlindberg/puppet/keys{/key_id}","collaborators_url":"https://api.github.com/repos/hlindberg/puppet/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/hlindberg/puppet/teams","hooks_url":"https://api.github.com/repos/hlindberg/puppet/hooks","issue_events_url":"https://api.github.com/repos/hlindberg/puppet/issues/events{/number}","events_url":"https://api.github.com/repos/hlindberg/puppet/events","assignees_url":"https://api.github.com/repos/hlindberg/puppet/assignees{/user}","branches_url":"https://api.github.com/repos/hlindberg/puppet/branches{/branch}","tags_url":"https://api.github.com/repos/hlindberg/puppet/tags","blobs_url":"https://api.github.com/repos/hlindberg/puppet/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/hlindberg/puppet/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/hlindberg/puppet/git/refs{/sha}","trees_url":"https://api.github.com/repos/hlindberg/puppet/git/trees{/sha}","statuses_url":"https://api.github.com/repos/hlindberg/puppet/statuses/{sha}","languages_url":"https://api.github.com/repos/hlindberg/puppet/languages","stargazers_url":"https://api.github.com/repos/hlindberg/puppet/stargazers","contributors_url":"https://api.github.com/repos/hlindberg/puppet/contributors","subscribers_url":"https://api.github.com/repos/hlindberg/puppet/subscribers","subscription_url":"https://api.github.com/repos/hlindberg/puppet/subscription","commits_url":"https://api.github.com/repos/hlindberg/puppet/commits{/sha}","git_commits_url":"https://api.github.com/repos/hlindberg/puppet/git/commits{/sha}","comments_url":"https://api.github.com/repos/hlindberg/puppet/comments{/number}","issue_comment_url":"https://api.github.com/repos/hlindberg/puppet/issues/comments{/number}","contents_url":"https://api.github.com/repos/hlindberg/puppet/contents/{+path}","compare_url":"https://api.github.com/repos/hlindberg/puppet/compare/{base}...{head}","merges_url":"https://api.github.com/repos/hlindberg/puppet/merges","archive_url":"https://api.github.com/repos/hlindberg/puppet/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/hlindberg/puppet/downloads","issues_url":"https://api.github.com/repos/hlindberg/puppet/issues{/number}","pulls_url":"https://api.github.com/repos/hlindberg/puppet/pulls{/number}","milestones_url":"https://api.github.com/repos/hlindberg/puppet/milestones{/number}","notifications_url":"https://api.github.com/repos/hlindberg/puppet/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/hlindberg/puppet/labels{/name}","releases_url":"https://api.github.com/repos/hlindberg/puppet/releases{/id}","deployments_url":"https://api.github.com/repos/hlindberg/puppet/deployments","created_at":"2012-09-05T21:08:12Z","updated_at":"2014-06-25T01:27:30Z","pushed_at":"2016-07-31T18:42:48Z","git_url":"git://github.com/hlindberg/puppet.git","ssh_url":"git@github.com:hlindberg/puppet.git","clone_url":"https://github.com/hlindberg/puppet.git","svn_url":"https://github.com/hlindberg/puppet","homepage":"http://www.puppetlabs.com/puppet/introduction/","size":157620,"stargazers_count":0,"watchers_count":0,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":7,"forks":0,"open_issues":7,"watchers":0,"default_branch":"master"}},"base":{"label":"puppetlabs:master","ref":"master","sha":"75d183f97ff60d45e15291ce8319d827cdb7d555","user":{"login":"puppetlabs","id":234268,"avatar_url":"https://avatars.githubusercontent.com/u/234268?v=3","gravatar_id":"","url":"https://api.github.com/users/puppetlabs","html_url":"https://github.com/puppetlabs","followers_url":"https://api.github.com/users/puppetlabs/followers","following_url":"https://api.github.com/users/puppetlabs/following{/other_user}","gists_url":"https://api.github.com/users/puppetlabs/gists{/gist_id}","starred_url":"https://api.github.com/users/puppetlabs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/puppetlabs/subscriptions","organizations_url":"https://api.github.com/users/puppetlabs/orgs","repos_url":"https://api.github.com/users/puppetlabs/repos","events_url":"https://api.github.com/users/puppetlabs/events{/privacy}","received_events_url":"https://api.github.com/users/puppetlabs/received_events","type":"Organization","site_admin":false},"repo":{"id":910744,"name":"puppet","full_name":"puppetlabs/puppet","owner":{"login":"puppetlabs","id":234268,"avatar_url":"https://avatars.githubusercontent.com/u/234268?v=3","gravatar_id":"","url":"https://api.github.com/users/puppetlabs","html_url":"https://github.com/puppetlabs","followers_url":"https://api.github.com/users/puppetlabs/followers","following_url":"https://api.github.com/users/puppetlabs/following{/other_user}","gists_url":"https://api.github.com/users/puppetlabs/gists{/gist_id}","starred_url":"https://api.github.com/users/puppetlabs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/puppetlabs/subscriptions","organizations_url":"https://api.github.com/users/puppetlabs/orgs","repos_url":"https://api.github.com/users/puppetlabs/repos","events_url":"https://api.github.com/users/puppetlabs/events{/privacy}","received_events_url":"https://api.github.com/users/puppetlabs/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/puppetlabs/puppet","description":"Server automation framework and application","fork":false,"url":"https://api.github.com/repos/puppetlabs/puppet","forks_url":"https://api.github.com/repos/puppetlabs/puppet/forks","keys_url":"https://api.github.com/repos/puppetlabs/puppet/keys{/key_id}","collaborators_url":"https://api.github.com/repos/puppetlabs/puppet/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/puppetlabs/puppet/teams","hooks_url":"https://api.github.com/repos/puppetlabs/puppet/hooks","issue_events_url":"https://api.github.com/repos/puppetlabs/puppet/issues/events{/number}","events_url":"https://api.github.com/repos/puppetlabs/puppet/events","assignees_url":"https://api.github.com/repos/puppetlabs/puppet/assignees{/user}","branches_url":"https://api.github.com/repos/puppetlabs/puppet/branches{/branch}","tags_url":"https://api.github.com/repos/puppetlabs/puppet/tags","blobs_url":"https://api.github.com/repos/puppetlabs/puppet/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/puppetlabs/puppet/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/puppetlabs/puppet/git/refs{/sha}","trees_url":"https://api.github.com/repos/puppetlabs/puppet/git/trees{/sha}","statuses_url":"https://api.github.com/repos/puppetlabs/puppet/statuses/{sha}","languages_url":"https://api.github.com/repos/puppetlabs/puppet/languages","stargazers_url":"https://api.github.com/repos/puppetlabs/puppet/stargazers","contributors_url":"https://api.github.com/repos/puppetlabs/puppet/contributors","subscribers_url":"https://api.github.com/repos/puppetlabs/puppet/subscribers","subscription_url":"https://api.github.com/repos/puppetlabs/puppet/subscription","commits_url":"https://api.github.com/repos/puppetlabs/puppet/commits{/sha}","git_commits_url":"https://api.github.com/repos/puppetlabs/puppet/git/commits{/sha}","comments_url":"https://api.github.com/repos/puppetlabs/puppet/comments{/number}","issue_comment_url":"https://api.github.com/repos/puppetlabs/puppet/issues/comments{/number}","contents_url":"https://api.github.com/repos/puppetlabs/puppet/contents/{+path}","compare_url":"https://api.github.com/repos/puppetlabs/puppet/compare/{base}...{head}","merges_url":"https://api.github.com/repos/puppetlabs/puppet/merges","archive_url":"https://api.github.com/repos/puppetlabs/puppet/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/puppetlabs/puppet/downloads","issues_url":"https://api.github.com/repos/puppetlabs/puppet/issues{/number}","pulls_url":"https://api.github.com/repos/puppetlabs/puppet/pulls{/number}","milestones_url":"https://api.github.com/repos/puppetlabs/puppet/milestones{/number}","notifications_url":"https://api.github.com/repos/puppetlabs/puppet/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/puppetlabs/puppet/labels{/name}","releases_url":"https://api.github.com/repos/puppetlabs/puppet/releases{/id}","deployments_url":"https://api.github.com/repos/puppetlabs/puppet/deployments","created_at":"2010-09-14T19:26:44Z","updated_at":"2016-08-01T06:13:11Z","pushed_at":"2016-07-31T18:45:21Z","git_url":"git://github.com/puppetlabs/puppet.git","ssh_url":"git@github.com:puppetlabs/puppet.git","clone_url":"https://github.com/puppetlabs/puppet.git","svn_url":"https://github.com/puppetlabs/puppet","homepage":"https://puppet.com/puppet/what-is-puppet","size":80284,"stargazers_count":4080,"watchers_count":4080,"language":"Ruby","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":1690,"mirror_url":null,"open_issues_count":56,"forks":1690,"open_issues":56,"watchers":4080,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/puppetlabs/puppet/pulls/5161"},"html":{"href":"https://github.com/puppetlabs/puppet/pull/5161"},"issue":{"href":"https://api.github.com/repos/puppetlabs/puppet/issues/5161"},"comments":{"href":"https://api.github.com/repos/puppetlabs/puppet/issues/5161/comments"},"review_comments":{"href":"https://api.github.com/repos/puppetlabs/puppet/pulls/5161/comments"},"review_comment":{"href":"https://api.github.com/repos/puppetlabs/puppet/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/puppetlabs/puppet/pulls/5161/commits"},"statuses":{"href":"https://api.github.com/repos/puppetlabs/puppet/statuses/72deb23c2a3af5cc8cbf393c3fc222767e0fd555"}}}}
{"actor":{"display_login":"thallgren"}}