{"action":"created","comment":{"url":"https://api.github.com/repos/stevenjack/cfndsl/pulls/comments/56740634","id":56740634,"diff_hunk":"@@ -0,0 +1,179 @@\n+require 'cfndsl/jsonable'\n+require 'cfndsl/names'\n+require 'cfndsl/aws/types'\n+require 'cfndsl/os/types'\n+\n+module CfnDsl\n+  # Handles the overall template object\n+  class OrchestrationTemplate < JSONable\n+    dsl_attr_setter :AWSTemplateFormatVersion, :Description\n+    dsl_content_object :Condition, :Parameter, :Output, :Resource, :Mapping\n+\n+    def initialize\n+      @AWSTemplateFormatVersion = '2010-09-09'\n+    end\n+\n+    @@globalRefs = {\n+      'AWS::NotificationARNs' => 1,\n+      'AWS::Region' => 1,\n+      'AWS::StackId' => 1,\n+      'AWS::StackName' => 1,\n+      'AWS::AccountId' => 1,\n+      'AWS::NoValue' => 1\n+    }\n+\n+    def valid_ref?(ref, origin = nil)\n+      ref = ref.to_s\n+      origin = origin.to_s if origin\n+\n+      return true if @@globalRefs.key?(ref)\n+\n+      return true if @Parameters && @Parameters.key?(ref)\n+\n+      if @Resources.key?(ref)\n+        return !origin || !@_resource_refs || !@_resource_refs[ref] || !@_resource_refs[ref].key?(origin)\n+      end\n+\n+      false\n+    end\n+\n+    def check_refs\n+      invalids = []\n+\n+      @_resource_refs = {}\n+      if @Resources\n+        @Resources.keys.each do |resource|\n+          @_resource_refs[resource.to_s] = @Resources[resource].references({})\n+        end\n+        @_resource_refs.keys.each do |origin|\n+          @_resource_refs[origin].keys.each do |ref|\n+            invalids.push \"Invalid Reference: Resource #{origin} refers to #{ref}\" unless valid_ref?(ref, origin)\n+          end\n+        end\n+      end\n+\n+      output_refs = {}\n+      if @Outputs\n+        @Outputs.keys.each do |resource|\n+          output_refs[resource.to_s] = @Outputs[resource].references({})\n+        end\n+        output_refs.keys.each do |origin|\n+          output_refs[origin].keys.each do |ref|\n+            invalids.push \"Invalid Reference: Output #{origin} refers to #{ref}\" unless valid_ref?(ref)\n+          end\n+        end\n+      end\n+\n+      invalids.empty? ? nil : invalids\n+    end\n+\n+    def self.create_types\n+      names = {}\n+      nametypes = {}\n+      template_types['Resources'].each_pair do |name, type|\n+        # Subclass ResourceDefintion and generate property methods\n+        klass = Class.new(CfnDsl::ResourceDefinition)\n+        klassname = name.split('::').join('_')\n+        type_module.const_set(klassname, klass)\n+        type['Properties'].each_pair do |pname, ptype|\n+          if ptype.instance_of?(String)\n+            create_klass = type_module.const_get(ptype)\n+\n+            klass.class_eval do\n+              CfnDsl.method_names(pname) do |method|\n+                define_method(method) do |*values, &block|\n+                  values.push create_klass.new if values.empty?\n+\n+                  @Properties ||= {}\n+                  @Properties[pname] = CfnDsl::PropertyDefinition.new(*values)\n+                  @Properties[pname].value.instance_eval(&block) if block\n+                  @Properties[pname].value\n+                end\n+              end\n+            end\n+          else\n+            # Array version\n+            sing_name = CfnDsl::Plurals.singularize(pname)\n+            create_klass = type_module.const_get(ptype[0])\n+            klass.class_eval do\n+              CfnDsl.method_names(pname) do |method|\n+                define_method(method) do |*values, &block|\n+                  values.push [] if values.empty?\n+                  @Properties ||= {}\n+                  @Properties[pname] ||= PropertyDefinition.new(*values)\n+                  @Properties[pname].value.instance_eval(&block) if block\n+                  @Properties[pname].value\n+                end\n+              end\n+\n+              CfnDsl.method_names(sing_name) do |method|\n+                define_method(method) do |value = nil, &block|\n+                  @Properties ||= {}\n+                  @Properties[pname] ||= PropertyDefinition.new([])\n+                  value = create_klass.new unless value\n+                  @Properties[pname].value.push value\n+                  value.instance_eval(&block) if block\n+                  value\n+                end\n+              end\n+            end\n+          end\n+        end\n+        parts = name.split('::')\n+        until parts.empty?\n+          abreve_name = parts.join('_')\n+          if names.key?(abreve_name)\n+            # this only happens if there is an ambiguity\n+            names[abreve_name] = nil\n+          else\n+            names[abreve_name] = type_module.const_get(klassname)\n+            nametypes[abreve_name] = name\n+          end\n+          parts.shift\n+        end\n+      end\n+\n+      # Define property setter methods for each of the unambiguous type names\n+      names.each_pair do |typename, type|\n+        next unless type\n+\n+        class_eval do\n+          CfnDsl.method_names(typename) do |method|\n+            define_method(method) do |name, *values, &block|\n+              name = name.to_s\n+              @Resources ||= {}\n+              resource = @Resources[name] ||= type.new(*values)\n+              resource.instance_eval(&block) if block\n+              resource.instance_variable_set('@Type', nametypes[typename])\n+              resource\n+            end\n+          end\n+        end\n+      end\n+    end\n+  end\n+\n+  class CloudFormationTemplate < OrchestrationTemplate\n+    def self.template_types\n+      CfnDsl::AWS::Types::Types_Internal","path":"lib/cfndsl/cloud_formation_template.rb","position":158,"original_position":158,"commit_id":"d3313cca5731ae583d378d46b34d19df7368c7a6","original_commit_id":"d3313cca5731ae583d378d46b34d19df7368c7a6","user":{"login":"stevenjack","id":527874,"avatar_url":"https://avatars.githubusercontent.com/u/527874?v=3","gravatar_id":"","url":"https://api.github.com/users/stevenjack","html_url":"https://github.com/stevenjack","followers_url":"https://api.github.com/users/stevenjack/followers","following_url":"https://api.github.com/users/stevenjack/following{/other_user}","gists_url":"https://api.github.com/users/stevenjack/gists{/gist_id}","starred_url":"https://api.github.com/users/stevenjack/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stevenjack/subscriptions","organizations_url":"https://api.github.com/users/stevenjack/orgs","repos_url":"https://api.github.com/users/stevenjack/repos","events_url":"https://api.github.com/users/stevenjack/events{/privacy}","received_events_url":"https://api.github.com/users/stevenjack/received_events","type":"User","site_admin":false},"body":"These `Internal` prefixes aren't going to stay, I need to work out a better name for these otherwise it's `.. AWS::Types::Types` which doesn't really make much sense.","created_at":"2016-03-19T01:09:22Z","updated_at":"2016-03-19T01:09:22Z","html_url":"https://github.com/stevenjack/cfndsl/pull/161#discussion_r56740634","pull_request_url":"https://api.github.com/repos/stevenjack/cfndsl/pulls/161","_links":{"self":{"href":"https://api.github.com/repos/stevenjack/cfndsl/pulls/comments/56740634"},"html":{"href":"https://github.com/stevenjack/cfndsl/pull/161#discussion_r56740634"},"pull_request":{"href":"https://api.github.com/repos/stevenjack/cfndsl/pulls/161"}}},"pull_request":{"url":"https://api.github.com/repos/stevenjack/cfndsl/pulls/161","id":63453991,"html_url":"https://github.com/stevenjack/cfndsl/pull/161","diff_url":"https://github.com/stevenjack/cfndsl/pull/161.diff","patch_url":"https://github.com/stevenjack/cfndsl/pull/161.patch","issue_url":"https://api.github.com/repos/stevenjack/cfndsl/issues/161","number":161,"state":"open","locked":false,"title":"Rubocop fixes","user":{"login":"stevenjack","id":527874,"avatar_url":"https://avatars.githubusercontent.com/u/527874?v=3","gravatar_id":"","url":"https://api.github.com/users/stevenjack","html_url":"https://github.com/stevenjack","followers_url":"https://api.github.com/users/stevenjack/followers","following_url":"https://api.github.com/users/stevenjack/following{/other_user}","gists_url":"https://api.github.com/users/stevenjack/gists{/gist_id}","starred_url":"https://api.github.com/users/stevenjack/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stevenjack/subscriptions","organizations_url":"https://api.github.com/users/stevenjack/orgs","repos_url":"https://api.github.com/users/stevenjack/repos","events_url":"https://api.github.com/users/stevenjack/events{/privacy}","received_events_url":"https://api.github.com/users/stevenjack/received_events","type":"User","site_admin":false},"body":"### Problem\r\n\r\nConsistency of the code is fairly poor and it would be nice to have a style guide that the gem adheres to.\r\n\r\n### Solution\r\n\r\nWorking on @johnf branch, fix the the set of standard cops then gradually introduce others such as the ruby 1.9 new hash syntax.\r\n\r\nBranch based off original start here: https://github.com/johnf/cfndsl/tree/rubocop","created_at":"2016-03-19T01:02:37Z","updated_at":"2016-03-19T01:09:22Z","closed_at":null,"merged_at":null,"merge_commit_sha":"000c2888fc28f99b5ae36715139c16878ab27303","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/stevenjack/cfndsl/pulls/161/commits","review_comments_url":"https://api.github.com/repos/stevenjack/cfndsl/pulls/161/comments","review_comment_url":"https://api.github.com/repos/stevenjack/cfndsl/pulls/comments{/number}","comments_url":"https://api.github.com/repos/stevenjack/cfndsl/issues/161/comments","statuses_url":"https://api.github.com/repos/stevenjack/cfndsl/statuses/d3313cca5731ae583d378d46b34d19df7368c7a6","head":{"label":"stevenjack:johnf_rubocop","ref":"johnf_rubocop","sha":"d3313cca5731ae583d378d46b34d19df7368c7a6","user":{"login":"stevenjack","id":527874,"avatar_url":"https://avatars.githubusercontent.com/u/527874?v=3","gravatar_id":"","url":"https://api.github.com/users/stevenjack","html_url":"https://github.com/stevenjack","followers_url":"https://api.github.com/users/stevenjack/followers","following_url":"https://api.github.com/users/stevenjack/following{/other_user}","gists_url":"https://api.github.com/users/stevenjack/gists{/gist_id}","starred_url":"https://api.github.com/users/stevenjack/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stevenjack/subscriptions","organizations_url":"https://api.github.com/users/stevenjack/orgs","repos_url":"https://api.github.com/users/stevenjack/repos","events_url":"https://api.github.com/users/stevenjack/events{/privacy}","received_events_url":"https://api.github.com/users/stevenjack/received_events","type":"User","site_admin":false},"repo":{"id":7137996,"name":"cfndsl","full_name":"stevenjack/cfndsl","owner":{"login":"stevenjack","id":527874,"avatar_url":"https://avatars.githubusercontent.com/u/527874?v=3","gravatar_id":"","url":"https://api.github.com/users/stevenjack","html_url":"https://github.com/stevenjack","followers_url":"https://api.github.com/users/stevenjack/followers","following_url":"https://api.github.com/users/stevenjack/following{/other_user}","gists_url":"https://api.github.com/users/stevenjack/gists{/gist_id}","starred_url":"https://api.github.com/users/stevenjack/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stevenjack/subscriptions","organizations_url":"https://api.github.com/users/stevenjack/orgs","repos_url":"https://api.github.com/users/stevenjack/repos","events_url":"https://api.github.com/users/stevenjack/events{/privacy}","received_events_url":"https://api.github.com/users/stevenjack/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/stevenjack/cfndsl","description":"A DSL for generating Amazon Web Services CloudFormation templates.","fork":false,"url":"https://api.github.com/repos/stevenjack/cfndsl","forks_url":"https://api.github.com/repos/stevenjack/cfndsl/forks","keys_url":"https://api.github.com/repos/stevenjack/cfndsl/keys{/key_id}","collaborators_url":"https://api.github.com/repos/stevenjack/cfndsl/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/stevenjack/cfndsl/teams","hooks_url":"https://api.github.com/repos/stevenjack/cfndsl/hooks","issue_events_url":"https://api.github.com/repos/stevenjack/cfndsl/issues/events{/number}","events_url":"https://api.github.com/repos/stevenjack/cfndsl/events","assignees_url":"https://api.github.com/repos/stevenjack/cfndsl/assignees{/user}","branches_url":"https://api.github.com/repos/stevenjack/cfndsl/branches{/branch}","tags_url":"https://api.github.com/repos/stevenjack/cfndsl/tags","blobs_url":"https://api.github.com/repos/stevenjack/cfndsl/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/stevenjack/cfndsl/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/stevenjack/cfndsl/git/refs{/sha}","trees_url":"https://api.github.com/repos/stevenjack/cfndsl/git/trees{/sha}","statuses_url":"https://api.github.com/repos/stevenjack/cfndsl/statuses/{sha}","languages_url":"https://api.github.com/repos/stevenjack/cfndsl/languages","stargazers_url":"https://api.github.com/repos/stevenjack/cfndsl/stargazers","contributors_url":"https://api.github.com/repos/stevenjack/cfndsl/contributors","subscribers_url":"https://api.github.com/repos/stevenjack/cfndsl/subscribers","subscription_url":"https://api.github.com/repos/stevenjack/cfndsl/subscription","commits_url":"https://api.github.com/repos/stevenjack/cfndsl/commits{/sha}","git_commits_url":"https://api.github.com/repos/stevenjack/cfndsl/git/commits{/sha}","comments_url":"https://api.github.com/repos/stevenjack/cfndsl/comments{/number}","issue_comment_url":"https://api.github.com/repos/stevenjack/cfndsl/issues/comments{/number}","contents_url":"https://api.github.com/repos/stevenjack/cfndsl/contents/{+path}","compare_url":"https://api.github.com/repos/stevenjack/cfndsl/compare/{base}...{head}","merges_url":"https://api.github.com/repos/stevenjack/cfndsl/merges","archive_url":"https://api.github.com/repos/stevenjack/cfndsl/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/stevenjack/cfndsl/downloads","issues_url":"https://api.github.com/repos/stevenjack/cfndsl/issues{/number}","pulls_url":"https://api.github.com/repos/stevenjack/cfndsl/pulls{/number}","milestones_url":"https://api.github.com/repos/stevenjack/cfndsl/milestones{/number}","notifications_url":"https://api.github.com/repos/stevenjack/cfndsl/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/stevenjack/cfndsl/labels{/name}","releases_url":"https://api.github.com/repos/stevenjack/cfndsl/releases{/id}","deployments_url":"https://api.github.com/repos/stevenjack/cfndsl/deployments","created_at":"2012-12-12T21:33:23Z","updated_at":"2016-03-17T17:35:46Z","pushed_at":"2016-03-19T01:02:38Z","git_url":"git://github.com/stevenjack/cfndsl.git","ssh_url":"git@github.com:stevenjack/cfndsl.git","clone_url":"https://github.com/stevenjack/cfndsl.git","svn_url":"https://github.com/stevenjack/cfndsl","homepage":"","size":379,"stargazers_count":186,"watchers_count":186,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":74,"mirror_url":null,"open_issues_count":22,"forks":74,"open_issues":22,"watchers":186,"default_branch":"master"}},"base":{"label":"stevenjack:master","ref":"master","sha":"e365b156d2d8d633fad9010019ffe30e79f77b15","user":{"login":"stevenjack","id":527874,"avatar_url":"https://avatars.githubusercontent.com/u/527874?v=3","gravatar_id":"","url":"https://api.github.com/users/stevenjack","html_url":"https://github.com/stevenjack","followers_url":"https://api.github.com/users/stevenjack/followers","following_url":"https://api.github.com/users/stevenjack/following{/other_user}","gists_url":"https://api.github.com/users/stevenjack/gists{/gist_id}","starred_url":"https://api.github.com/users/stevenjack/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stevenjack/subscriptions","organizations_url":"https://api.github.com/users/stevenjack/orgs","repos_url":"https://api.github.com/users/stevenjack/repos","events_url":"https://api.github.com/users/stevenjack/events{/privacy}","received_events_url":"https://api.github.com/users/stevenjack/received_events","type":"User","site_admin":false},"repo":{"id":7137996,"name":"cfndsl","full_name":"stevenjack/cfndsl","owner":{"login":"stevenjack","id":527874,"avatar_url":"https://avatars.githubusercontent.com/u/527874?v=3","gravatar_id":"","url":"https://api.github.com/users/stevenjack","html_url":"https://github.com/stevenjack","followers_url":"https://api.github.com/users/stevenjack/followers","following_url":"https://api.github.com/users/stevenjack/following{/other_user}","gists_url":"https://api.github.com/users/stevenjack/gists{/gist_id}","starred_url":"https://api.github.com/users/stevenjack/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stevenjack/subscriptions","organizations_url":"https://api.github.com/users/stevenjack/orgs","repos_url":"https://api.github.com/users/stevenjack/repos","events_url":"https://api.github.com/users/stevenjack/events{/privacy}","received_events_url":"https://api.github.com/users/stevenjack/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/stevenjack/cfndsl","description":"A DSL for generating Amazon Web Services CloudFormation templates.","fork":false,"url":"https://api.github.com/repos/stevenjack/cfndsl","forks_url":"https://api.github.com/repos/stevenjack/cfndsl/forks","keys_url":"https://api.github.com/repos/stevenjack/cfndsl/keys{/key_id}","collaborators_url":"https://api.github.com/repos/stevenjack/cfndsl/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/stevenjack/cfndsl/teams","hooks_url":"https://api.github.com/repos/stevenjack/cfndsl/hooks","issue_events_url":"https://api.github.com/repos/stevenjack/cfndsl/issues/events{/number}","events_url":"https://api.github.com/repos/stevenjack/cfndsl/events","assignees_url":"https://api.github.com/repos/stevenjack/cfndsl/assignees{/user}","branches_url":"https://api.github.com/repos/stevenjack/cfndsl/branches{/branch}","tags_url":"https://api.github.com/repos/stevenjack/cfndsl/tags","blobs_url":"https://api.github.com/repos/stevenjack/cfndsl/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/stevenjack/cfndsl/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/stevenjack/cfndsl/git/refs{/sha}","trees_url":"https://api.github.com/repos/stevenjack/cfndsl/git/trees{/sha}","statuses_url":"https://api.github.com/repos/stevenjack/cfndsl/statuses/{sha}","languages_url":"https://api.github.com/repos/stevenjack/cfndsl/languages","stargazers_url":"https://api.github.com/repos/stevenjack/cfndsl/stargazers","contributors_url":"https://api.github.com/repos/stevenjack/cfndsl/contributors","subscribers_url":"https://api.github.com/repos/stevenjack/cfndsl/subscribers","subscription_url":"https://api.github.com/repos/stevenjack/cfndsl/subscription","commits_url":"https://api.github.com/repos/stevenjack/cfndsl/commits{/sha}","git_commits_url":"https://api.github.com/repos/stevenjack/cfndsl/git/commits{/sha}","comments_url":"https://api.github.com/repos/stevenjack/cfndsl/comments{/number}","issue_comment_url":"https://api.github.com/repos/stevenjack/cfndsl/issues/comments{/number}","contents_url":"https://api.github.com/repos/stevenjack/cfndsl/contents/{+path}","compare_url":"https://api.github.com/repos/stevenjack/cfndsl/compare/{base}...{head}","merges_url":"https://api.github.com/repos/stevenjack/cfndsl/merges","archive_url":"https://api.github.com/repos/stevenjack/cfndsl/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/stevenjack/cfndsl/downloads","issues_url":"https://api.github.com/repos/stevenjack/cfndsl/issues{/number}","pulls_url":"https://api.github.com/repos/stevenjack/cfndsl/pulls{/number}","milestones_url":"https://api.github.com/repos/stevenjack/cfndsl/milestones{/number}","notifications_url":"https://api.github.com/repos/stevenjack/cfndsl/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/stevenjack/cfndsl/labels{/name}","releases_url":"https://api.github.com/repos/stevenjack/cfndsl/releases{/id}","deployments_url":"https://api.github.com/repos/stevenjack/cfndsl/deployments","created_at":"2012-12-12T21:33:23Z","updated_at":"2016-03-17T17:35:46Z","pushed_at":"2016-03-19T01:02:38Z","git_url":"git://github.com/stevenjack/cfndsl.git","ssh_url":"git@github.com:stevenjack/cfndsl.git","clone_url":"https://github.com/stevenjack/cfndsl.git","svn_url":"https://github.com/stevenjack/cfndsl","homepage":"","size":379,"stargazers_count":186,"watchers_count":186,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":74,"mirror_url":null,"open_issues_count":22,"forks":74,"open_issues":22,"watchers":186,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/stevenjack/cfndsl/pulls/161"},"html":{"href":"https://github.com/stevenjack/cfndsl/pull/161"},"issue":{"href":"https://api.github.com/repos/stevenjack/cfndsl/issues/161"},"comments":{"href":"https://api.github.com/repos/stevenjack/cfndsl/issues/161/comments"},"review_comments":{"href":"https://api.github.com/repos/stevenjack/cfndsl/pulls/161/comments"},"review_comment":{"href":"https://api.github.com/repos/stevenjack/cfndsl/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/stevenjack/cfndsl/pulls/161/commits"},"statuses":{"href":"https://api.github.com/repos/stevenjack/cfndsl/statuses/d3313cca5731ae583d378d46b34d19df7368c7a6"}}}}