{"action":"created","comment":{"url":"https://api.github.com/repos/rossettistone/espinita/pulls/comments/30265169","id":30265169,"diff_hunk":"@@ -56,6 +56,66 @@ def as_user(user, &block)\n \n     end\n \n+    def history_from_audits_for(attributes)\n+      attributes = arrayify(attributes)\n+      attributes = attributes.map{ |p| p.to_s } # for consistency, ensure that we're working with strings, not symbols\n+      raise ArgumentError, \"At least one of the specified columns does not exist or is not audited.\" if (attributes - self.class.permitted_columns).any?\n+\n+      audits = relevant_audits(self.audits, attributes)\n+\n+      property_history = audits.map do |a|\n+        result = Hash.new\n+        (a.audited_changes.keys.map{|k|k.to_s} & attributes).each do |key|\n+          result[key.to_sym] = a.audited_changes[key.to_sym].last\n+        end\n+        result[:changed_at] = a.created_at.localtime.strftime('%Y-%m-%dT%l:%M:%S%z')\n+        result\n+      end\n+      return property_history\n+    end\n+\n+    def restore_attributes!(attributes, datetime)\n+      attributes = arrayify(attributes)\n+      attributes = attributes.map{ |p| p.to_s } # for consistency, ensure that we're working with strings, not symbols\n+      raise ArgumentError, \"At least one of the specified columns does not exist or is not audited.\" if (attributes - self.class.permitted_columns).any?\n+\n+      changes = {}\n+\n+      attributes.each do |attrib|\n+        audits = relevant_audits(self.audits, attrib)\n+        audits.each do |a|\n+          if a.created_at < datetime\n+            restore_val = a.audited_changes[attrib.to_sym].last\n+            unless restore_val == self[attrib]\n+              changes[attrib] = restore_val\n+            end\n+            break # successfully restored from an audit - exit now\n+          end\n+        end\n+        if !changes[attrib].present? && (datetime < audits.last.created_at)\n+          changes[attrib] = audits.last.audited_changes[attrib.to_sym].first\n+        end\n+      end\n+\n+      self.update_attributes(changes)","path":"lib/espinita/auditor_behavior.rb","position":45,"original_position":45,"commit_id":"37b81c91d64463534de7128ed069f2b30141111b","original_commit_id":"37b81c91d64463534de7128ed069f2b30141111b","user":{"login":"hayesgm","id":271024,"avatar_url":"https://avatars.githubusercontent.com/u/271024?v=3","gravatar_id":"","url":"https://api.github.com/users/hayesgm","html_url":"https://github.com/hayesgm","followers_url":"https://api.github.com/users/hayesgm/followers","following_url":"https://api.github.com/users/hayesgm/following{/other_user}","gists_url":"https://api.github.com/users/hayesgm/gists{/gist_id}","starred_url":"https://api.github.com/users/hayesgm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hayesgm/subscriptions","organizations_url":"https://api.github.com/users/hayesgm/orgs","repos_url":"https://api.github.com/users/hayesgm/repos","events_url":"https://api.github.com/users/hayesgm/events{/privacy}","received_events_url":"https://api.github.com/users/hayesgm/received_events","type":"User","site_admin":false},"body":"double check this is the *exact* AR method you want. questions on validations, etc. maybe `validate: false`?","created_at":"2015-05-13T19:11:59Z","updated_at":"2015-05-13T19:11:59Z","html_url":"https://github.com/rossettistone/espinita/pull/1#discussion_r30265169","pull_request_url":"https://api.github.com/repos/rossettistone/espinita/pulls/1","_links":{"self":{"href":"https://api.github.com/repos/rossettistone/espinita/pulls/comments/30265169"},"html":{"href":"https://github.com/rossettistone/espinita/pull/1#discussion_r30265169"},"pull_request":{"href":"https://api.github.com/repos/rossettistone/espinita/pulls/1"}}},"pull_request":{"url":"https://api.github.com/repos/rossettistone/espinita/pulls/1","id":35358104,"html_url":"https://github.com/rossettistone/espinita/pull/1","diff_url":"https://github.com/rossettistone/espinita/pull/1.diff","patch_url":"https://github.com/rossettistone/espinita/pull/1.patch","issue_url":"https://api.github.com/repos/rossettistone/espinita/issues/1","number":1,"state":"open","locked":false,"title":"Feature/restoration","user":{"login":"rossettistone","id":1834981,"avatar_url":"https://avatars.githubusercontent.com/u/1834981?v=3","gravatar_id":"","url":"https://api.github.com/users/rossettistone","html_url":"https://github.com/rossettistone","followers_url":"https://api.github.com/users/rossettistone/followers","following_url":"https://api.github.com/users/rossettistone/following{/other_user}","gists_url":"https://api.github.com/users/rossettistone/gists{/gist_id}","starred_url":"https://api.github.com/users/rossettistone/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rossettistone/subscriptions","organizations_url":"https://api.github.com/users/rossettistone/orgs","repos_url":"https://api.github.com/users/rossettistone/repos","events_url":"https://api.github.com/users/rossettistone/events{/privacy}","received_events_url":"https://api.github.com/users/rossettistone/received_events","type":"User","site_admin":false},"body":"Sample PR for making notes. Real PR will be against fork.","created_at":"2015-05-13T18:48:12Z","updated_at":"2015-05-13T19:11:59Z","closed_at":null,"merged_at":null,"merge_commit_sha":"3fc8930e059e8046347b132d24f54f2d476f0f8a","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/rossettistone/espinita/pulls/1/commits","review_comments_url":"https://api.github.com/repos/rossettistone/espinita/pulls/1/comments","review_comment_url":"https://api.github.com/repos/rossettistone/espinita/pulls/comments{/number}","comments_url":"https://api.github.com/repos/rossettistone/espinita/issues/1/comments","statuses_url":"https://api.github.com/repos/rossettistone/espinita/statuses/37b81c91d64463534de7128ed069f2b30141111b","head":{"label":"rossettistone:feature/restoration","ref":"feature/restoration","sha":"37b81c91d64463534de7128ed069f2b30141111b","user":{"login":"rossettistone","id":1834981,"avatar_url":"https://avatars.githubusercontent.com/u/1834981?v=3","gravatar_id":"","url":"https://api.github.com/users/rossettistone","html_url":"https://github.com/rossettistone","followers_url":"https://api.github.com/users/rossettistone/followers","following_url":"https://api.github.com/users/rossettistone/following{/other_user}","gists_url":"https://api.github.com/users/rossettistone/gists{/gist_id}","starred_url":"https://api.github.com/users/rossettistone/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rossettistone/subscriptions","organizations_url":"https://api.github.com/users/rossettistone/orgs","repos_url":"https://api.github.com/users/rossettistone/repos","events_url":"https://api.github.com/users/rossettistone/events{/privacy}","received_events_url":"https://api.github.com/users/rossettistone/received_events","type":"User","site_admin":false},"repo":{"id":33049667,"name":"espinita","full_name":"rossettistone/espinita","owner":{"login":"rossettistone","id":1834981,"avatar_url":"https://avatars.githubusercontent.com/u/1834981?v=3","gravatar_id":"","url":"https://api.github.com/users/rossettistone","html_url":"https://github.com/rossettistone","followers_url":"https://api.github.com/users/rossettistone/followers","following_url":"https://api.github.com/users/rossettistone/following{/other_user}","gists_url":"https://api.github.com/users/rossettistone/gists{/gist_id}","starred_url":"https://api.github.com/users/rossettistone/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rossettistone/subscriptions","organizations_url":"https://api.github.com/users/rossettistone/orgs","repos_url":"https://api.github.com/users/rossettistone/repos","events_url":"https://api.github.com/users/rossettistone/events{/privacy}","received_events_url":"https://api.github.com/users/rossettistone/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/rossettistone/espinita","description":"Audit activerecord models like a boss (and works with rails 4!)","fork":true,"url":"https://api.github.com/repos/rossettistone/espinita","forks_url":"https://api.github.com/repos/rossettistone/espinita/forks","keys_url":"https://api.github.com/repos/rossettistone/espinita/keys{/key_id}","collaborators_url":"https://api.github.com/repos/rossettistone/espinita/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/rossettistone/espinita/teams","hooks_url":"https://api.github.com/repos/rossettistone/espinita/hooks","issue_events_url":"https://api.github.com/repos/rossettistone/espinita/issues/events{/number}","events_url":"https://api.github.com/repos/rossettistone/espinita/events","assignees_url":"https://api.github.com/repos/rossettistone/espinita/assignees{/user}","branches_url":"https://api.github.com/repos/rossettistone/espinita/branches{/branch}","tags_url":"https://api.github.com/repos/rossettistone/espinita/tags","blobs_url":"https://api.github.com/repos/rossettistone/espinita/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/rossettistone/espinita/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/rossettistone/espinita/git/refs{/sha}","trees_url":"https://api.github.com/repos/rossettistone/espinita/git/trees{/sha}","statuses_url":"https://api.github.com/repos/rossettistone/espinita/statuses/{sha}","languages_url":"https://api.github.com/repos/rossettistone/espinita/languages","stargazers_url":"https://api.github.com/repos/rossettistone/espinita/stargazers","contributors_url":"https://api.github.com/repos/rossettistone/espinita/contributors","subscribers_url":"https://api.github.com/repos/rossettistone/espinita/subscribers","subscription_url":"https://api.github.com/repos/rossettistone/espinita/subscription","commits_url":"https://api.github.com/repos/rossettistone/espinita/commits{/sha}","git_commits_url":"https://api.github.com/repos/rossettistone/espinita/git/commits{/sha}","comments_url":"https://api.github.com/repos/rossettistone/espinita/comments{/number}","issue_comment_url":"https://api.github.com/repos/rossettistone/espinita/issues/comments{/number}","contents_url":"https://api.github.com/repos/rossettistone/espinita/contents/{+path}","compare_url":"https://api.github.com/repos/rossettistone/espinita/compare/{base}...{head}","merges_url":"https://api.github.com/repos/rossettistone/espinita/merges","archive_url":"https://api.github.com/repos/rossettistone/espinita/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/rossettistone/espinita/downloads","issues_url":"https://api.github.com/repos/rossettistone/espinita/issues{/number}","pulls_url":"https://api.github.com/repos/rossettistone/espinita/pulls{/number}","milestones_url":"https://api.github.com/repos/rossettistone/espinita/milestones{/number}","notifications_url":"https://api.github.com/repos/rossettistone/espinita/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/rossettistone/espinita/labels{/name}","releases_url":"https://api.github.com/repos/rossettistone/espinita/releases{/id}","created_at":"2015-03-28T20:46:27Z","updated_at":"2015-03-28T20:46:28Z","pushed_at":"2015-05-13T18:48:12Z","git_url":"git://github.com/rossettistone/espinita.git","ssh_url":"git@github.com:rossettistone/espinita.git","clone_url":"https://github.com/rossettistone/espinita.git","svn_url":"https://github.com/rossettistone/espinita","homepage":"","size":240,"stargazers_count":0,"watchers_count":0,"language":"Ruby","has_issues":false,"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":"rossettistone:master","ref":"master","sha":"2ba8bd992287cb3111c9a5b96c9eedf1fcabb0f1","user":{"login":"rossettistone","id":1834981,"avatar_url":"https://avatars.githubusercontent.com/u/1834981?v=3","gravatar_id":"","url":"https://api.github.com/users/rossettistone","html_url":"https://github.com/rossettistone","followers_url":"https://api.github.com/users/rossettistone/followers","following_url":"https://api.github.com/users/rossettistone/following{/other_user}","gists_url":"https://api.github.com/users/rossettistone/gists{/gist_id}","starred_url":"https://api.github.com/users/rossettistone/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rossettistone/subscriptions","organizations_url":"https://api.github.com/users/rossettistone/orgs","repos_url":"https://api.github.com/users/rossettistone/repos","events_url":"https://api.github.com/users/rossettistone/events{/privacy}","received_events_url":"https://api.github.com/users/rossettistone/received_events","type":"User","site_admin":false},"repo":{"id":33049667,"name":"espinita","full_name":"rossettistone/espinita","owner":{"login":"rossettistone","id":1834981,"avatar_url":"https://avatars.githubusercontent.com/u/1834981?v=3","gravatar_id":"","url":"https://api.github.com/users/rossettistone","html_url":"https://github.com/rossettistone","followers_url":"https://api.github.com/users/rossettistone/followers","following_url":"https://api.github.com/users/rossettistone/following{/other_user}","gists_url":"https://api.github.com/users/rossettistone/gists{/gist_id}","starred_url":"https://api.github.com/users/rossettistone/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rossettistone/subscriptions","organizations_url":"https://api.github.com/users/rossettistone/orgs","repos_url":"https://api.github.com/users/rossettistone/repos","events_url":"https://api.github.com/users/rossettistone/events{/privacy}","received_events_url":"https://api.github.com/users/rossettistone/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/rossettistone/espinita","description":"Audit activerecord models like a boss (and works with rails 4!)","fork":true,"url":"https://api.github.com/repos/rossettistone/espinita","forks_url":"https://api.github.com/repos/rossettistone/espinita/forks","keys_url":"https://api.github.com/repos/rossettistone/espinita/keys{/key_id}","collaborators_url":"https://api.github.com/repos/rossettistone/espinita/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/rossettistone/espinita/teams","hooks_url":"https://api.github.com/repos/rossettistone/espinita/hooks","issue_events_url":"https://api.github.com/repos/rossettistone/espinita/issues/events{/number}","events_url":"https://api.github.com/repos/rossettistone/espinita/events","assignees_url":"https://api.github.com/repos/rossettistone/espinita/assignees{/user}","branches_url":"https://api.github.com/repos/rossettistone/espinita/branches{/branch}","tags_url":"https://api.github.com/repos/rossettistone/espinita/tags","blobs_url":"https://api.github.com/repos/rossettistone/espinita/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/rossettistone/espinita/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/rossettistone/espinita/git/refs{/sha}","trees_url":"https://api.github.com/repos/rossettistone/espinita/git/trees{/sha}","statuses_url":"https://api.github.com/repos/rossettistone/espinita/statuses/{sha}","languages_url":"https://api.github.com/repos/rossettistone/espinita/languages","stargazers_url":"https://api.github.com/repos/rossettistone/espinita/stargazers","contributors_url":"https://api.github.com/repos/rossettistone/espinita/contributors","subscribers_url":"https://api.github.com/repos/rossettistone/espinita/subscribers","subscription_url":"https://api.github.com/repos/rossettistone/espinita/subscription","commits_url":"https://api.github.com/repos/rossettistone/espinita/commits{/sha}","git_commits_url":"https://api.github.com/repos/rossettistone/espinita/git/commits{/sha}","comments_url":"https://api.github.com/repos/rossettistone/espinita/comments{/number}","issue_comment_url":"https://api.github.com/repos/rossettistone/espinita/issues/comments{/number}","contents_url":"https://api.github.com/repos/rossettistone/espinita/contents/{+path}","compare_url":"https://api.github.com/repos/rossettistone/espinita/compare/{base}...{head}","merges_url":"https://api.github.com/repos/rossettistone/espinita/merges","archive_url":"https://api.github.com/repos/rossettistone/espinita/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/rossettistone/espinita/downloads","issues_url":"https://api.github.com/repos/rossettistone/espinita/issues{/number}","pulls_url":"https://api.github.com/repos/rossettistone/espinita/pulls{/number}","milestones_url":"https://api.github.com/repos/rossettistone/espinita/milestones{/number}","notifications_url":"https://api.github.com/repos/rossettistone/espinita/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/rossettistone/espinita/labels{/name}","releases_url":"https://api.github.com/repos/rossettistone/espinita/releases{/id}","created_at":"2015-03-28T20:46:27Z","updated_at":"2015-03-28T20:46:28Z","pushed_at":"2015-05-13T18:48:12Z","git_url":"git://github.com/rossettistone/espinita.git","ssh_url":"git@github.com:rossettistone/espinita.git","clone_url":"https://github.com/rossettistone/espinita.git","svn_url":"https://github.com/rossettistone/espinita","homepage":"","size":240,"stargazers_count":0,"watchers_count":0,"language":"Ruby","has_issues":false,"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/rossettistone/espinita/pulls/1"},"html":{"href":"https://github.com/rossettistone/espinita/pull/1"},"issue":{"href":"https://api.github.com/repos/rossettistone/espinita/issues/1"},"comments":{"href":"https://api.github.com/repos/rossettistone/espinita/issues/1/comments"},"review_comments":{"href":"https://api.github.com/repos/rossettistone/espinita/pulls/1/comments"},"review_comment":{"href":"https://api.github.com/repos/rossettistone/espinita/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/rossettistone/espinita/pulls/1/commits"},"statuses":{"href":"https://api.github.com/repos/rossettistone/espinita/statuses/37b81c91d64463534de7128ed069f2b30141111b"}}}}