{"action":"created","comment":{"url":"https://api.github.com/repos/kazuooooo/objectable-hash/pulls/comments/93585036","pull_request_review_id":14114921,"id":93585036,"diff_hunk":"@@ -7,56 +7,72 @@\n module ObjectableJSON\n   class << self\n \n-    def parse(json_or_hash)\n+    def parse(json_or_hash, ancestors = [])\n       hash = hashed?(json_or_hash) ? json_or_hash : JSON.parse(json_or_hash)\n       objs =\n-        hash.map do |klass_name, attrs|\n-          attributes = classified_or_raw_attributes(attrs)\n-          klass      = create_klass(klass_name, attributes)\n-          klass.new(attributes)\n-        end\n+          hash.map do |klass_name, attrs|\n+            ancestors << klass_name\n+            attributes = build_attributes(attrs, ancestors.dup)\n+            klass      = create_klass(klass_name, attributes)\n+            klass.new(attributes[:attributes])\n+          end\n       single_object?(objs) ? objs.first : objs\n     end\n \n \n     private\n-    def classified_or_raw_attributes(attrs)\n+    def build_attributes(attrs, ancestors)\n       attributes = {}\n       attrs.each do |attr_key, attr_val|\n         attributes[attr_key] =\n-          if klassable?({ attr_key => attr_val })\n-            parse({ attr_key => attr_val })\n-          elsif is_collection?(attr_val)\n-            attr_val.map { |v| klassable?(v) ? parse(v) : v }\n-          else\n-            attr_val\n-          end\n+            if klassable?({ attr_key => attr_val })\n+              parse({ attr_key => attr_val }, ancestors.dup)\n+            elsif is_collection?(attr_val)\n+              attr_val.map { |v| klassable?(v) ? parse(v) : v }\n+            else\n+              attr_val\n+            end\n       end\n-      attributes\n+      { attributes: attributes, ancestors: ancestors }\n     end\n \n     # create class\n     # @param [String] class name\n     # @param [Hash] attributes_hash is set as class instance attributes named key\n     # @return [Class] created class object\n     def create_klass(name, attributes_hash)\n-      return name.camelize.constantize if const_defined?(name.camelize)\n+      define_ancestors(attributes_hash[:ancestors])\n \n-      klass      =\n-        Class.new(Object) do\n-          attr_reader(* attributes_hash.keys)\n+      # return name.camelize.constantize if const_defined?(name.camelize)\n+      klass_name = build_name_space(attributes_hash[:ancestors])\n+      klass_name.constantize.class_eval do\n+        attr_reader(* attributes_hash[:attributes].keys)\n \n-          def initialize(attributes)\n-            attributes.each do |k, v|\n-              instance_variable_set(\"@#{k}\", v)\n-            end\n+        def initialize(attributes)\n+          attributes.each do |k, v|\n+            instance_variable_set(\"@#{k}\", v)\n           end\n         end\n-      klass_name = name.camelize\n-      Object.const_set(klass_name, klass)\n+      end\n       klass_name.constantize\n     end\n \n+    def define_ancestors(ancestors)\n+      ancestors.reduce([]) do |name_space, klass|","path":"lib/objectable_json.rb","position":80,"original_position":80,"commit_id":"1e57aff99e86b593c487d5d3676a5d61aac984fb","original_commit_id":"1e57aff99e86b593c487d5d3676a5d61aac984fb","user":{"login":"kazuooooo","id":6919381,"avatar_url":"https://avatars.githubusercontent.com/u/6919381?v=3","gravatar_id":"","url":"https://api.github.com/users/kazuooooo","html_url":"https://github.com/kazuooooo","followers_url":"https://api.github.com/users/kazuooooo/followers","following_url":"https://api.github.com/users/kazuooooo/following{/other_user}","gists_url":"https://api.github.com/users/kazuooooo/gists{/gist_id}","starred_url":"https://api.github.com/users/kazuooooo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kazuooooo/subscriptions","organizations_url":"https://api.github.com/users/kazuooooo/orgs","repos_url":"https://api.github.com/users/kazuooooo/repos","events_url":"https://api.github.com/users/kazuooooo/events{/privacy}","received_events_url":"https://api.github.com/users/kazuooooo/received_events","type":"User","site_admin":false},"body":"__[rubocop]__\n* Use `each_with_object` instead of `reduce`.\n\n<!-- Comment by [SideCI](https://sideci.com) -->","created_at":"2016-12-22T08:52:26Z","updated_at":"2016-12-22T08:52:26Z","html_url":"https://github.com/kazuooooo/objectable-hash/pull/6#discussion_r93585036","pull_request_url":"https://api.github.com/repos/kazuooooo/objectable-hash/pulls/6","_links":{"self":{"href":"https://api.github.com/repos/kazuooooo/objectable-hash/pulls/comments/93585036"},"html":{"href":"https://github.com/kazuooooo/objectable-hash/pull/6#discussion_r93585036"},"pull_request":{"href":"https://api.github.com/repos/kazuooooo/objectable-hash/pulls/6"}}},"pull_request":{"url":"https://api.github.com/repos/kazuooooo/objectable-hash/pulls/6","id":99068092,"html_url":"https://github.com/kazuooooo/objectable-hash/pull/6","diff_url":"https://github.com/kazuooooo/objectable-hash/pull/6.diff","patch_url":"https://github.com/kazuooooo/objectable-hash/pull/6.patch","issue_url":"https://api.github.com/repos/kazuooooo/objectable-hash/issues/6","number":6,"state":"open","locked":false,"title":"Kazuooooo/develop3","user":{"login":"kazuooooo","id":6919381,"avatar_url":"https://avatars.githubusercontent.com/u/6919381?v=3","gravatar_id":"","url":"https://api.github.com/users/kazuooooo","html_url":"https://github.com/kazuooooo","followers_url":"https://api.github.com/users/kazuooooo/followers","following_url":"https://api.github.com/users/kazuooooo/following{/other_user}","gists_url":"https://api.github.com/users/kazuooooo/gists{/gist_id}","starred_url":"https://api.github.com/users/kazuooooo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kazuooooo/subscriptions","organizations_url":"https://api.github.com/users/kazuooooo/orgs","repos_url":"https://api.github.com/users/kazuooooo/repos","events_url":"https://api.github.com/users/kazuooooo/events{/privacy}","received_events_url":"https://api.github.com/users/kazuooooo/received_events","type":"User","site_admin":false},"body":" * nested name space\r\n * extract json file","created_at":"2016-12-22T08:52:19Z","updated_at":"2016-12-22T08:52:26Z","closed_at":null,"merged_at":null,"merge_commit_sha":"c5416c60a65d33fe59989ad000a5b9467e3cae88","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/kazuooooo/objectable-hash/pulls/6/commits","review_comments_url":"https://api.github.com/repos/kazuooooo/objectable-hash/pulls/6/comments","review_comment_url":"https://api.github.com/repos/kazuooooo/objectable-hash/pulls/comments{/number}","comments_url":"https://api.github.com/repos/kazuooooo/objectable-hash/issues/6/comments","statuses_url":"https://api.github.com/repos/kazuooooo/objectable-hash/statuses/1e57aff99e86b593c487d5d3676a5d61aac984fb","head":{"label":"kazuooooo:kazuooooo/develop3","ref":"kazuooooo/develop3","sha":"1e57aff99e86b593c487d5d3676a5d61aac984fb","user":{"login":"kazuooooo","id":6919381,"avatar_url":"https://avatars.githubusercontent.com/u/6919381?v=3","gravatar_id":"","url":"https://api.github.com/users/kazuooooo","html_url":"https://github.com/kazuooooo","followers_url":"https://api.github.com/users/kazuooooo/followers","following_url":"https://api.github.com/users/kazuooooo/following{/other_user}","gists_url":"https://api.github.com/users/kazuooooo/gists{/gist_id}","starred_url":"https://api.github.com/users/kazuooooo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kazuooooo/subscriptions","organizations_url":"https://api.github.com/users/kazuooooo/orgs","repos_url":"https://api.github.com/users/kazuooooo/repos","events_url":"https://api.github.com/users/kazuooooo/events{/privacy}","received_events_url":"https://api.github.com/users/kazuooooo/received_events","type":"User","site_admin":false},"repo":{"id":76372694,"name":"objectable-hash","full_name":"kazuooooo/objectable-hash","owner":{"login":"kazuooooo","id":6919381,"avatar_url":"https://avatars.githubusercontent.com/u/6919381?v=3","gravatar_id":"","url":"https://api.github.com/users/kazuooooo","html_url":"https://github.com/kazuooooo","followers_url":"https://api.github.com/users/kazuooooo/followers","following_url":"https://api.github.com/users/kazuooooo/following{/other_user}","gists_url":"https://api.github.com/users/kazuooooo/gists{/gist_id}","starred_url":"https://api.github.com/users/kazuooooo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kazuooooo/subscriptions","organizations_url":"https://api.github.com/users/kazuooooo/orgs","repos_url":"https://api.github.com/users/kazuooooo/repos","events_url":"https://api.github.com/users/kazuooooo/events{/privacy}","received_events_url":"https://api.github.com/users/kazuooooo/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/kazuooooo/objectable-hash","description":null,"fork":false,"url":"https://api.github.com/repos/kazuooooo/objectable-hash","forks_url":"https://api.github.com/repos/kazuooooo/objectable-hash/forks","keys_url":"https://api.github.com/repos/kazuooooo/objectable-hash/keys{/key_id}","collaborators_url":"https://api.github.com/repos/kazuooooo/objectable-hash/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/kazuooooo/objectable-hash/teams","hooks_url":"https://api.github.com/repos/kazuooooo/objectable-hash/hooks","issue_events_url":"https://api.github.com/repos/kazuooooo/objectable-hash/issues/events{/number}","events_url":"https://api.github.com/repos/kazuooooo/objectable-hash/events","assignees_url":"https://api.github.com/repos/kazuooooo/objectable-hash/assignees{/user}","branches_url":"https://api.github.com/repos/kazuooooo/objectable-hash/branches{/branch}","tags_url":"https://api.github.com/repos/kazuooooo/objectable-hash/tags","blobs_url":"https://api.github.com/repos/kazuooooo/objectable-hash/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/kazuooooo/objectable-hash/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/kazuooooo/objectable-hash/git/refs{/sha}","trees_url":"https://api.github.com/repos/kazuooooo/objectable-hash/git/trees{/sha}","statuses_url":"https://api.github.com/repos/kazuooooo/objectable-hash/statuses/{sha}","languages_url":"https://api.github.com/repos/kazuooooo/objectable-hash/languages","stargazers_url":"https://api.github.com/repos/kazuooooo/objectable-hash/stargazers","contributors_url":"https://api.github.com/repos/kazuooooo/objectable-hash/contributors","subscribers_url":"https://api.github.com/repos/kazuooooo/objectable-hash/subscribers","subscription_url":"https://api.github.com/repos/kazuooooo/objectable-hash/subscription","commits_url":"https://api.github.com/repos/kazuooooo/objectable-hash/commits{/sha}","git_commits_url":"https://api.github.com/repos/kazuooooo/objectable-hash/git/commits{/sha}","comments_url":"https://api.github.com/repos/kazuooooo/objectable-hash/comments{/number}","issue_comment_url":"https://api.github.com/repos/kazuooooo/objectable-hash/issues/comments{/number}","contents_url":"https://api.github.com/repos/kazuooooo/objectable-hash/contents/{+path}","compare_url":"https://api.github.com/repos/kazuooooo/objectable-hash/compare/{base}...{head}","merges_url":"https://api.github.com/repos/kazuooooo/objectable-hash/merges","archive_url":"https://api.github.com/repos/kazuooooo/objectable-hash/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/kazuooooo/objectable-hash/downloads","issues_url":"https://api.github.com/repos/kazuooooo/objectable-hash/issues{/number}","pulls_url":"https://api.github.com/repos/kazuooooo/objectable-hash/pulls{/number}","milestones_url":"https://api.github.com/repos/kazuooooo/objectable-hash/milestones{/number}","notifications_url":"https://api.github.com/repos/kazuooooo/objectable-hash/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/kazuooooo/objectable-hash/labels{/name}","releases_url":"https://api.github.com/repos/kazuooooo/objectable-hash/releases{/id}","deployments_url":"https://api.github.com/repos/kazuooooo/objectable-hash/deployments","created_at":"2016-12-13T15:42:49Z","updated_at":"2016-12-13T15:48:44Z","pushed_at":"2016-12-22T08:52:20Z","git_url":"git://github.com/kazuooooo/objectable-hash.git","ssh_url":"git@github.com:kazuooooo/objectable-hash.git","clone_url":"https://github.com/kazuooooo/objectable-hash.git","svn_url":"https://github.com/kazuooooo/objectable-hash","homepage":null,"size":28,"stargazers_count":0,"watchers_count":0,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"base":{"label":"kazuooooo:develop","ref":"develop","sha":"5fa1acccfea024dfa6fd9bde86857ec865fb4acd","user":{"login":"kazuooooo","id":6919381,"avatar_url":"https://avatars.githubusercontent.com/u/6919381?v=3","gravatar_id":"","url":"https://api.github.com/users/kazuooooo","html_url":"https://github.com/kazuooooo","followers_url":"https://api.github.com/users/kazuooooo/followers","following_url":"https://api.github.com/users/kazuooooo/following{/other_user}","gists_url":"https://api.github.com/users/kazuooooo/gists{/gist_id}","starred_url":"https://api.github.com/users/kazuooooo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kazuooooo/subscriptions","organizations_url":"https://api.github.com/users/kazuooooo/orgs","repos_url":"https://api.github.com/users/kazuooooo/repos","events_url":"https://api.github.com/users/kazuooooo/events{/privacy}","received_events_url":"https://api.github.com/users/kazuooooo/received_events","type":"User","site_admin":false},"repo":{"id":76372694,"name":"objectable-hash","full_name":"kazuooooo/objectable-hash","owner":{"login":"kazuooooo","id":6919381,"avatar_url":"https://avatars.githubusercontent.com/u/6919381?v=3","gravatar_id":"","url":"https://api.github.com/users/kazuooooo","html_url":"https://github.com/kazuooooo","followers_url":"https://api.github.com/users/kazuooooo/followers","following_url":"https://api.github.com/users/kazuooooo/following{/other_user}","gists_url":"https://api.github.com/users/kazuooooo/gists{/gist_id}","starred_url":"https://api.github.com/users/kazuooooo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kazuooooo/subscriptions","organizations_url":"https://api.github.com/users/kazuooooo/orgs","repos_url":"https://api.github.com/users/kazuooooo/repos","events_url":"https://api.github.com/users/kazuooooo/events{/privacy}","received_events_url":"https://api.github.com/users/kazuooooo/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/kazuooooo/objectable-hash","description":null,"fork":false,"url":"https://api.github.com/repos/kazuooooo/objectable-hash","forks_url":"https://api.github.com/repos/kazuooooo/objectable-hash/forks","keys_url":"https://api.github.com/repos/kazuooooo/objectable-hash/keys{/key_id}","collaborators_url":"https://api.github.com/repos/kazuooooo/objectable-hash/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/kazuooooo/objectable-hash/teams","hooks_url":"https://api.github.com/repos/kazuooooo/objectable-hash/hooks","issue_events_url":"https://api.github.com/repos/kazuooooo/objectable-hash/issues/events{/number}","events_url":"https://api.github.com/repos/kazuooooo/objectable-hash/events","assignees_url":"https://api.github.com/repos/kazuooooo/objectable-hash/assignees{/user}","branches_url":"https://api.github.com/repos/kazuooooo/objectable-hash/branches{/branch}","tags_url":"https://api.github.com/repos/kazuooooo/objectable-hash/tags","blobs_url":"https://api.github.com/repos/kazuooooo/objectable-hash/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/kazuooooo/objectable-hash/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/kazuooooo/objectable-hash/git/refs{/sha}","trees_url":"https://api.github.com/repos/kazuooooo/objectable-hash/git/trees{/sha}","statuses_url":"https://api.github.com/repos/kazuooooo/objectable-hash/statuses/{sha}","languages_url":"https://api.github.com/repos/kazuooooo/objectable-hash/languages","stargazers_url":"https://api.github.com/repos/kazuooooo/objectable-hash/stargazers","contributors_url":"https://api.github.com/repos/kazuooooo/objectable-hash/contributors","subscribers_url":"https://api.github.com/repos/kazuooooo/objectable-hash/subscribers","subscription_url":"https://api.github.com/repos/kazuooooo/objectable-hash/subscription","commits_url":"https://api.github.com/repos/kazuooooo/objectable-hash/commits{/sha}","git_commits_url":"https://api.github.com/repos/kazuooooo/objectable-hash/git/commits{/sha}","comments_url":"https://api.github.com/repos/kazuooooo/objectable-hash/comments{/number}","issue_comment_url":"https://api.github.com/repos/kazuooooo/objectable-hash/issues/comments{/number}","contents_url":"https://api.github.com/repos/kazuooooo/objectable-hash/contents/{+path}","compare_url":"https://api.github.com/repos/kazuooooo/objectable-hash/compare/{base}...{head}","merges_url":"https://api.github.com/repos/kazuooooo/objectable-hash/merges","archive_url":"https://api.github.com/repos/kazuooooo/objectable-hash/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/kazuooooo/objectable-hash/downloads","issues_url":"https://api.github.com/repos/kazuooooo/objectable-hash/issues{/number}","pulls_url":"https://api.github.com/repos/kazuooooo/objectable-hash/pulls{/number}","milestones_url":"https://api.github.com/repos/kazuooooo/objectable-hash/milestones{/number}","notifications_url":"https://api.github.com/repos/kazuooooo/objectable-hash/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/kazuooooo/objectable-hash/labels{/name}","releases_url":"https://api.github.com/repos/kazuooooo/objectable-hash/releases{/id}","deployments_url":"https://api.github.com/repos/kazuooooo/objectable-hash/deployments","created_at":"2016-12-13T15:42:49Z","updated_at":"2016-12-13T15:48:44Z","pushed_at":"2016-12-22T08:52:20Z","git_url":"git://github.com/kazuooooo/objectable-hash.git","ssh_url":"git@github.com:kazuooooo/objectable-hash.git","clone_url":"https://github.com/kazuooooo/objectable-hash.git","svn_url":"https://github.com/kazuooooo/objectable-hash","homepage":null,"size":28,"stargazers_count":0,"watchers_count":0,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/kazuooooo/objectable-hash/pulls/6"},"html":{"href":"https://github.com/kazuooooo/objectable-hash/pull/6"},"issue":{"href":"https://api.github.com/repos/kazuooooo/objectable-hash/issues/6"},"comments":{"href":"https://api.github.com/repos/kazuooooo/objectable-hash/issues/6/comments"},"review_comments":{"href":"https://api.github.com/repos/kazuooooo/objectable-hash/pulls/6/comments"},"review_comment":{"href":"https://api.github.com/repos/kazuooooo/objectable-hash/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/kazuooooo/objectable-hash/pulls/6/commits"},"statuses":{"href":"https://api.github.com/repos/kazuooooo/objectable-hash/statuses/1e57aff99e86b593c487d5d3676a5d61aac984fb"}}}}
{"actor":{"display_login":"kazuooooo"}}