{"action":"created","comment":{"url":"https://api.github.com/repos/solnic/transproc/pulls/comments/32133418","id":32133418,"diff_hunk":"@@ -244,7 +244,9 @@ def nest!(hash, root, keys)\n \n       if nest_keys.size > 0\n         child = Hash[nest_keys.zip(nest_keys.map { |key| hash.delete(key) })]\n-        hash.update(root => child)\n+        old_nest = hash[root]\n+        new_nest = old_nest.is_a?(Hash) ? old_nest.merge(child) : child\n+        hash.update(root => new_nest)","path":"lib/transproc/hash.rb","position":7,"original_position":7,"commit_id":"6351863399fe71cd85675181a3106d91201b5581","original_commit_id":"6351863399fe71cd85675181a3106d91201b5581","user":{"login":"AMHOL","id":1582784,"avatar_url":"https://avatars.githubusercontent.com/u/1582784?v=3","gravatar_id":"","url":"https://api.github.com/users/AMHOL","html_url":"https://github.com/AMHOL","followers_url":"https://api.github.com/users/AMHOL/followers","following_url":"https://api.github.com/users/AMHOL/following{/other_user}","gists_url":"https://api.github.com/users/AMHOL/gists{/gist_id}","starred_url":"https://api.github.com/users/AMHOL/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/AMHOL/subscriptions","organizations_url":"https://api.github.com/users/AMHOL/orgs","repos_url":"https://api.github.com/users/AMHOL/repos","events_url":"https://api.github.com/users/AMHOL/events{/privacy}","received_events_url":"https://api.github.com/users/AMHOL/received_events","type":"User","site_admin":false},"body":"Could go with:\r\n\r\n```ruby\r\nhash.update(root => hash.fetch(root, {}).merge(child))\r\n```","created_at":"2015-06-10T15:58:16Z","updated_at":"2015-06-10T15:58:16Z","html_url":"https://github.com/solnic/transproc/pull/47#discussion_r32133418","pull_request_url":"https://api.github.com/repos/solnic/transproc/pulls/47","_links":{"self":{"href":"https://api.github.com/repos/solnic/transproc/pulls/comments/32133418"},"html":{"href":"https://github.com/solnic/transproc/pull/47#discussion_r32133418"},"pull_request":{"href":"https://api.github.com/repos/solnic/transproc/pulls/47"}}},"pull_request":{"url":"https://api.github.com/repos/solnic/transproc/pulls/47","id":37367992,"html_url":"https://github.com/solnic/transproc/pull/47","diff_url":"https://github.com/solnic/transproc/pull/47.diff","patch_url":"https://github.com/solnic/transproc/pull/47.patch","issue_url":"https://api.github.com/repos/solnic/transproc/issues/47","number":47,"state":"open","locked":false,"title":"Both `nest` and `wrap` transformations add data to the existing subhash","user":{"login":"nepalez","id":1526628,"avatar_url":"https://avatars.githubusercontent.com/u/1526628?v=3","gravatar_id":"","url":"https://api.github.com/users/nepalez","html_url":"https://github.com/nepalez","followers_url":"https://api.github.com/users/nepalez/followers","following_url":"https://api.github.com/users/nepalez/following{/other_user}","gists_url":"https://api.github.com/users/nepalez/gists{/gist_id}","starred_url":"https://api.github.com/users/nepalez/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nepalez/subscriptions","organizations_url":"https://api.github.com/users/nepalez/orgs","repos_url":"https://api.github.com/users/nepalez/repos","events_url":"https://api.github.com/users/nepalez/events{/privacy}","received_events_url":"https://api.github.com/users/nepalez/received_events","type":"User","site_admin":false},"body":"Apply to `wrap` just the same logics as to `group`, allowing to wrap data step-by-step\r\n\r\n1) `nest`\r\n\r\nIf the key, to which the data should be wrapped, is already exist\r\nand contains a hash, then new data are added to that hash, while preserving\r\nthe existing data.\r\n\r\n```ruby\r\n  fn = t(:nest, :foo, :baz)\r\n  source = { foo: { bar: :BAR }, baz: :BAZ }\r\n\r\n  # Old behaviour\r\n  fn[source] # => { foo: { baz: :BAZ } }\r\n\r\n  # New behaviour\r\n  fn[source] # => { foo: { bar: :BAR, baz: :BAZ } }\r\n```\r\n\r\nIn case the value under the key is not a hash, new data rewrite the old ones\r\nas before:\r\n\r\n```ruby\r\n  source = { foo: :FOO, baz: :BAZ }\r\n  fn[source] # => { foo: { baz: :BAZ } }\r\n```\r\n\r\n2) `wrap`\r\n\r\nThe operation applies the updated `nest` to array of tuples.","created_at":"2015-06-10T14:59:07Z","updated_at":"2015-06-10T15:58:16Z","closed_at":null,"merged_at":null,"merge_commit_sha":"6638ecb92715f7a115f2fd19580bcb651a9fff34","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/solnic/transproc/pulls/47/commits","review_comments_url":"https://api.github.com/repos/solnic/transproc/pulls/47/comments","review_comment_url":"https://api.github.com/repos/solnic/transproc/pulls/comments{/number}","comments_url":"https://api.github.com/repos/solnic/transproc/issues/47/comments","statuses_url":"https://api.github.com/repos/solnic/transproc/statuses/6351863399fe71cd85675181a3106d91201b5581","head":{"label":"solnic:wrap","ref":"wrap","sha":"6351863399fe71cd85675181a3106d91201b5581","user":{"login":"solnic","id":1066,"avatar_url":"https://avatars.githubusercontent.com/u/1066?v=3","gravatar_id":"","url":"https://api.github.com/users/solnic","html_url":"https://github.com/solnic","followers_url":"https://api.github.com/users/solnic/followers","following_url":"https://api.github.com/users/solnic/following{/other_user}","gists_url":"https://api.github.com/users/solnic/gists{/gist_id}","starred_url":"https://api.github.com/users/solnic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/solnic/subscriptions","organizations_url":"https://api.github.com/users/solnic/orgs","repos_url":"https://api.github.com/users/solnic/repos","events_url":"https://api.github.com/users/solnic/events{/privacy}","received_events_url":"https://api.github.com/users/solnic/received_events","type":"User","site_admin":false},"repo":{"id":28452477,"name":"transproc","full_name":"solnic/transproc","owner":{"login":"solnic","id":1066,"avatar_url":"https://avatars.githubusercontent.com/u/1066?v=3","gravatar_id":"","url":"https://api.github.com/users/solnic","html_url":"https://github.com/solnic","followers_url":"https://api.github.com/users/solnic/followers","following_url":"https://api.github.com/users/solnic/following{/other_user}","gists_url":"https://api.github.com/users/solnic/gists{/gist_id}","starred_url":"https://api.github.com/users/solnic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/solnic/subscriptions","organizations_url":"https://api.github.com/users/solnic/orgs","repos_url":"https://api.github.com/users/solnic/repos","events_url":"https://api.github.com/users/solnic/events{/privacy}","received_events_url":"https://api.github.com/users/solnic/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/solnic/transproc","description":"Transform Ruby objects in functional style","fork":false,"url":"https://api.github.com/repos/solnic/transproc","forks_url":"https://api.github.com/repos/solnic/transproc/forks","keys_url":"https://api.github.com/repos/solnic/transproc/keys{/key_id}","collaborators_url":"https://api.github.com/repos/solnic/transproc/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/solnic/transproc/teams","hooks_url":"https://api.github.com/repos/solnic/transproc/hooks","issue_events_url":"https://api.github.com/repos/solnic/transproc/issues/events{/number}","events_url":"https://api.github.com/repos/solnic/transproc/events","assignees_url":"https://api.github.com/repos/solnic/transproc/assignees{/user}","branches_url":"https://api.github.com/repos/solnic/transproc/branches{/branch}","tags_url":"https://api.github.com/repos/solnic/transproc/tags","blobs_url":"https://api.github.com/repos/solnic/transproc/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/solnic/transproc/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/solnic/transproc/git/refs{/sha}","trees_url":"https://api.github.com/repos/solnic/transproc/git/trees{/sha}","statuses_url":"https://api.github.com/repos/solnic/transproc/statuses/{sha}","languages_url":"https://api.github.com/repos/solnic/transproc/languages","stargazers_url":"https://api.github.com/repos/solnic/transproc/stargazers","contributors_url":"https://api.github.com/repos/solnic/transproc/contributors","subscribers_url":"https://api.github.com/repos/solnic/transproc/subscribers","subscription_url":"https://api.github.com/repos/solnic/transproc/subscription","commits_url":"https://api.github.com/repos/solnic/transproc/commits{/sha}","git_commits_url":"https://api.github.com/repos/solnic/transproc/git/commits{/sha}","comments_url":"https://api.github.com/repos/solnic/transproc/comments{/number}","issue_comment_url":"https://api.github.com/repos/solnic/transproc/issues/comments{/number}","contents_url":"https://api.github.com/repos/solnic/transproc/contents/{+path}","compare_url":"https://api.github.com/repos/solnic/transproc/compare/{base}...{head}","merges_url":"https://api.github.com/repos/solnic/transproc/merges","archive_url":"https://api.github.com/repos/solnic/transproc/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/solnic/transproc/downloads","issues_url":"https://api.github.com/repos/solnic/transproc/issues{/number}","pulls_url":"https://api.github.com/repos/solnic/transproc/pulls{/number}","milestones_url":"https://api.github.com/repos/solnic/transproc/milestones{/number}","notifications_url":"https://api.github.com/repos/solnic/transproc/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/solnic/transproc/labels{/name}","releases_url":"https://api.github.com/repos/solnic/transproc/releases{/id}","created_at":"2014-12-24T15:15:27Z","updated_at":"2015-06-10T00:26:59Z","pushed_at":"2015-06-10T14:59:08Z","git_url":"git://github.com/solnic/transproc.git","ssh_url":"git@github.com:solnic/transproc.git","clone_url":"https://github.com/solnic/transproc.git","svn_url":"https://github.com/solnic/transproc","homepage":"http://solnic.github.io/transproc/","size":970,"stargazers_count":91,"watchers_count":91,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":7,"mirror_url":null,"open_issues_count":4,"forks":7,"open_issues":4,"watchers":91,"default_branch":"master"}},"base":{"label":"solnic:master","ref":"master","sha":"7ef3363cf90d3df4a159bf5db2a95b373289bf21","user":{"login":"solnic","id":1066,"avatar_url":"https://avatars.githubusercontent.com/u/1066?v=3","gravatar_id":"","url":"https://api.github.com/users/solnic","html_url":"https://github.com/solnic","followers_url":"https://api.github.com/users/solnic/followers","following_url":"https://api.github.com/users/solnic/following{/other_user}","gists_url":"https://api.github.com/users/solnic/gists{/gist_id}","starred_url":"https://api.github.com/users/solnic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/solnic/subscriptions","organizations_url":"https://api.github.com/users/solnic/orgs","repos_url":"https://api.github.com/users/solnic/repos","events_url":"https://api.github.com/users/solnic/events{/privacy}","received_events_url":"https://api.github.com/users/solnic/received_events","type":"User","site_admin":false},"repo":{"id":28452477,"name":"transproc","full_name":"solnic/transproc","owner":{"login":"solnic","id":1066,"avatar_url":"https://avatars.githubusercontent.com/u/1066?v=3","gravatar_id":"","url":"https://api.github.com/users/solnic","html_url":"https://github.com/solnic","followers_url":"https://api.github.com/users/solnic/followers","following_url":"https://api.github.com/users/solnic/following{/other_user}","gists_url":"https://api.github.com/users/solnic/gists{/gist_id}","starred_url":"https://api.github.com/users/solnic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/solnic/subscriptions","organizations_url":"https://api.github.com/users/solnic/orgs","repos_url":"https://api.github.com/users/solnic/repos","events_url":"https://api.github.com/users/solnic/events{/privacy}","received_events_url":"https://api.github.com/users/solnic/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/solnic/transproc","description":"Transform Ruby objects in functional style","fork":false,"url":"https://api.github.com/repos/solnic/transproc","forks_url":"https://api.github.com/repos/solnic/transproc/forks","keys_url":"https://api.github.com/repos/solnic/transproc/keys{/key_id}","collaborators_url":"https://api.github.com/repos/solnic/transproc/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/solnic/transproc/teams","hooks_url":"https://api.github.com/repos/solnic/transproc/hooks","issue_events_url":"https://api.github.com/repos/solnic/transproc/issues/events{/number}","events_url":"https://api.github.com/repos/solnic/transproc/events","assignees_url":"https://api.github.com/repos/solnic/transproc/assignees{/user}","branches_url":"https://api.github.com/repos/solnic/transproc/branches{/branch}","tags_url":"https://api.github.com/repos/solnic/transproc/tags","blobs_url":"https://api.github.com/repos/solnic/transproc/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/solnic/transproc/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/solnic/transproc/git/refs{/sha}","trees_url":"https://api.github.com/repos/solnic/transproc/git/trees{/sha}","statuses_url":"https://api.github.com/repos/solnic/transproc/statuses/{sha}","languages_url":"https://api.github.com/repos/solnic/transproc/languages","stargazers_url":"https://api.github.com/repos/solnic/transproc/stargazers","contributors_url":"https://api.github.com/repos/solnic/transproc/contributors","subscribers_url":"https://api.github.com/repos/solnic/transproc/subscribers","subscription_url":"https://api.github.com/repos/solnic/transproc/subscription","commits_url":"https://api.github.com/repos/solnic/transproc/commits{/sha}","git_commits_url":"https://api.github.com/repos/solnic/transproc/git/commits{/sha}","comments_url":"https://api.github.com/repos/solnic/transproc/comments{/number}","issue_comment_url":"https://api.github.com/repos/solnic/transproc/issues/comments{/number}","contents_url":"https://api.github.com/repos/solnic/transproc/contents/{+path}","compare_url":"https://api.github.com/repos/solnic/transproc/compare/{base}...{head}","merges_url":"https://api.github.com/repos/solnic/transproc/merges","archive_url":"https://api.github.com/repos/solnic/transproc/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/solnic/transproc/downloads","issues_url":"https://api.github.com/repos/solnic/transproc/issues{/number}","pulls_url":"https://api.github.com/repos/solnic/transproc/pulls{/number}","milestones_url":"https://api.github.com/repos/solnic/transproc/milestones{/number}","notifications_url":"https://api.github.com/repos/solnic/transproc/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/solnic/transproc/labels{/name}","releases_url":"https://api.github.com/repos/solnic/transproc/releases{/id}","created_at":"2014-12-24T15:15:27Z","updated_at":"2015-06-10T00:26:59Z","pushed_at":"2015-06-10T14:59:08Z","git_url":"git://github.com/solnic/transproc.git","ssh_url":"git@github.com:solnic/transproc.git","clone_url":"https://github.com/solnic/transproc.git","svn_url":"https://github.com/solnic/transproc","homepage":"http://solnic.github.io/transproc/","size":970,"stargazers_count":91,"watchers_count":91,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":7,"mirror_url":null,"open_issues_count":4,"forks":7,"open_issues":4,"watchers":91,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/solnic/transproc/pulls/47"},"html":{"href":"https://github.com/solnic/transproc/pull/47"},"issue":{"href":"https://api.github.com/repos/solnic/transproc/issues/47"},"comments":{"href":"https://api.github.com/repos/solnic/transproc/issues/47/comments"},"review_comments":{"href":"https://api.github.com/repos/solnic/transproc/pulls/47/comments"},"review_comment":{"href":"https://api.github.com/repos/solnic/transproc/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/solnic/transproc/pulls/47/commits"},"statuses":{"href":"https://api.github.com/repos/solnic/transproc/statuses/6351863399fe71cd85675181a3106d91201b5581"}}}}