GitHub PullRequestReviewCommentEvent at 2014-06-13 14:03:42
Repository: rails
Actor: sgrif
Payload: {"action":"created","comment":{"url":"https://api.github.com/repos/rails/rails/pulls/comments/13751351","id":13751351,"diff_hunk":"@@ -0,0 +1,61 @@\n+module ActiveRecord\n+  class Attribute # :nodoc:\n+    class << self\n+      def from_database(value, type)\n+        FromDatabase.new(value, type)\n+      end\n+\n+      def from_user(value, type)\n+        FromUser.new(value, type)\n+      end\n+    end\n+\n+    attr_reader :value_before_type_cast, :type\n+\n+    # This method should not be called directly.\n+    # Use #from_database or #from_user\n+    def initialize(value_before_type_cast, type)\n+      @value_before_type_cast = value_before_type_cast\n+      @type = type\n+    end\n+\n+    def value\n+      @value = type_cast(value_before_type_cast) unless defined?(@value)","path":"activerecord/lib/active_record/attribute.rb","position":23,"original_position":23,"commit_id":"f47414a82adaece6f39841a6e0d7093739b43596","original_commit_id":"f47414a82adaece6f39841a6e0d7093739b43596","user":{"login":"sgrif","id":1529387,"avatar_url":"https://avatars.githubusercontent.com/u/1529387?","gravatar_id":"0f674817f8c6e149518f0a4b4ad3d560","url":"https://api.github.com/users/sgrif","html_url":"https://github.com/sgrif","followers_url":"https://api.github.com/users/sgrif/followers","following_url":"https://api.github.com/users/sgrif/following{/other_user}","gists_url":"https://api.github.com/users/sgrif/gists{/gist_id}","starred_url":"https://api.github.com/users/sgrif/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sgrif/subscriptions","organizations_url":"https://api.github.com/users/sgrif/orgs","repos_url":"https://api.github.com/users/sgrif/repos","events_url":"https://api.github.com/users/sgrif/events{/privacy}","received_events_url":"https://api.github.com/users/sgrif/received_events","type":"User","site_admin":false},"body":"My concern was that `type_cast` can return falsy values, and we'd like to avoid performing that computation multiple times. That said, I can't imagine any branch that ends with `nil` or `false` being that expensive. Any thoughts? Worth a benchmark?","created_at":"2014-06-13T14:03:42Z","updated_at":"2014-06-13T14:03:42Z","html_url":"https://github.com/rails/rails/pull/15593#discussion_r13751351","pull_request_url":"https://api.github.com/repos/rails/rails/pulls/15593","_links":{"self":{"href":"https://api.github.com/repos/rails/rails/pulls/comments/13751351"},"html":{"href":"https://github.com/rails/rails/pull/15593#discussion_r13751351"},"pull_request":{"href":"https://api.github.com/repos/rails/rails/pulls/15593"}}},"pull_request":{"url":"https://api.github.com/repos/rails/rails/pulls/15593","id":16908159,"html_url":"https://github.com/rails/rails/pull/15593","diff_url":"https://github.com/rails/rails/pull/15593.diff","patch_url":"https://github.com/rails/rails/pull/15593.patch","issue_url":"https://api.github.com/repos/rails/rails/issues/15593","number":15593,"state":"open","title":"Introduce an Attribute object to handle the type casting dance","user":{"login":"sgrif","id":1529387,"avatar_url":"https://avatars.githubusercontent.com/u/1529387?","gravatar_id":"0f674817f8c6e149518f0a4b4ad3d560","url":"https://api.github.com/users/sgrif","html_url":"https://github.com/sgrif","followers_url":"https://api.github.com/users/sgrif/followers","following_url":"https://api.github.com/users/sgrif/following{/other_user}","gists_url":"https://api.github.com/users/sgrif/gists{/gist_id}","starred_url":"https://api.github.com/users/sgrif/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sgrif/subscriptions","organizations_url":"https://api.github.com/users/sgrif/orgs","repos_url":"https://api.github.com/users/sgrif/repos","events_url":"https://api.github.com/users/sgrif/events{/privacy}","received_events_url":"https://api.github.com/users/sgrif/received_events","type":"User","site_admin":false},"body":"Depends on #15429 and includes the changes from that PR as well. There's a lot more that can be moved to these, but this felt like a good place to introduce the object. Plans are:\r\n\r\n- Remove all knowledge of type casting from the columns, beyond a\r\n  reference to the `cast_type`\r\n- Move `type_cast_for_database` to these objects\r\n- Potentially make them mutable, introduce a state machine, and have\r\n  dirty checking handled here as well\r\n- Move `attribute`, `decorate_attribute`, and anything else that\r\n  modifies types to mess with this object, not the columns hash\r\n- Introduce a collection object to manage these, and reduce allocations","created_at":"2014-06-09T21:03:51Z","updated_at":"2014-06-13T14:03:42Z","closed_at":null,"merged_at":null,"merge_commit_sha":"c5936e25d3199c7af5b60f40b374602e180f2811","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/rails/rails/pulls/15593/commits","review_comments_url":"https://api.github.com/repos/rails/rails/pulls/15593/comments","review_comment_url":"https://api.github.com/repos/rails/rails/pulls/comments/{number}","comments_url":"https://api.github.com/repos/rails/rails/issues/15593/comments","statuses_url":"https://api.github.com/repos/rails/rails/statuses/f47414a82adaece6f39841a6e0d7093739b43596","head":{"label":"sgrif:sg-attribute","ref":"sg-attribute","sha":"f47414a82adaece6f39841a6e0d7093739b43596","user":{"login":"sgrif","id":1529387,"avatar_url":"https://avatars.githubusercontent.com/u/1529387?","gravatar_id":"0f674817f8c6e149518f0a4b4ad3d560","url":"https://api.github.com/users/sgrif","html_url":"https://github.com/sgrif","followers_url":"https://api.github.com/users/sgrif/followers","following_url":"https://api.github.com/users/sgrif/following{/other_user}","gists_url":"https://api.github.com/users/sgrif/gists{/gist_id}","starred_url":"https://api.github.com/users/sgrif/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sgrif/subscriptions","organizations_url":"https://api.github.com/users/sgrif/orgs","repos_url":"https://api.github.com/users/sgrif/repos","events_url":"https://api.github.com/users/sgrif/events{/privacy}","received_events_url":"https://api.github.com/users/sgrif/received_events","type":"User","site_admin":false},"repo":{"id":12094762,"name":"rails","full_name":"sgrif/rails","owner":{"login":"sgrif","id":1529387,"avatar_url":"https://avatars.githubusercontent.com/u/1529387?","gravatar_id":"0f674817f8c6e149518f0a4b4ad3d560","url":"https://api.github.com/users/sgrif","html_url":"https://github.com/sgrif","followers_url":"https://api.github.com/users/sgrif/followers","following_url":"https://api.github.com/users/sgrif/following{/other_user}","gists_url":"https://api.github.com/users/sgrif/gists{/gist_id}","starred_url":"https://api.github.com/users/sgrif/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sgrif/subscriptions","organizations_url":"https://api.github.com/users/sgrif/orgs","repos_url":"https://api.github.com/users/sgrif/repos","events_url":"https://api.github.com/users/sgrif/events{/privacy}","received_events_url":"https://api.github.com/users/sgrif/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/sgrif/rails","description":"Ruby on Rails","fork":true,"url":"https://api.github.com/repos/sgrif/rails","forks_url":"https://api.github.com/repos/sgrif/rails/forks","keys_url":"https://api.github.com/repos/sgrif/rails/keys{/key_id}","collaborators_url":"https://api.github.com/repos/sgrif/rails/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/sgrif/rails/teams","hooks_url":"https://api.github.com/repos/sgrif/rails/hooks","issue_events_url":"https://api.github.com/repos/sgrif/rails/issues/events{/number}","events_url":"https://api.github.com/repos/sgrif/rails/events","assignees_url":"https://api.github.com/repos/sgrif/rails/assignees{/user}","branches_url":"https://api.github.com/repos/sgrif/rails/branches{/branch}","tags_url":"https://api.github.com/repos/sgrif/rails/tags","blobs_url":"https://api.github.com/repos/sgrif/rails/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/sgrif/rails/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/sgrif/rails/git/refs{/sha}","trees_url":"https://api.github.com/repos/sgrif/rails/git/trees{/sha}","statuses_url":"https://api.github.com/repos/sgrif/rails/statuses/{sha}","languages_url":"https://api.github.com/repos/sgrif/rails/languages","stargazers_url":"https://api.github.com/repos/sgrif/rails/stargazers","contributors_url":"https://api.github.com/repos/sgrif/rails/contributors","subscribers_url":"https://api.github.com/repos/sgrif/rails/subscribers","subscription_url":"https://api.github.com/repos/sgrif/rails/subscription","commits_url":"https://api.github.com/repos/sgrif/rails/commits{/sha}","git_commits_url":"https://api.github.com/repos/sgrif/rails/git/commits{/sha}","comments_url":"https://api.github.com/repos/sgrif/rails/comments{/number}","issue_comment_url":"https://api.github.com/repos/sgrif/rails/issues/comments/{number}","contents_url":"https://api.github.com/repos/sgrif/rails/contents/{+path}","compare_url":"https://api.github.com/repos/sgrif/rails/compare/{base}...{head}","merges_url":"https://api.github.com/repos/sgrif/rails/merges","archive_url":"https://api.github.com/repos/sgrif/rails/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/sgrif/rails/downloads","issues_url":"https://api.github.com/repos/sgrif/rails/issues{/number}","pulls_url":"https://api.github.com/repos/sgrif/rails/pulls{/number}","milestones_url":"https://api.github.com/repos/sgrif/rails/milestones{/number}","notifications_url":"https://api.github.com/repos/sgrif/rails/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/sgrif/rails/labels{/name}","releases_url":"https://api.github.com/repos/sgrif/rails/releases{/id}","created_at":"2013-08-13T22:42:15Z","updated_at":"2014-06-13T13:56:54Z","pushed_at":"2014-06-13T13:56:54Z","git_url":"git://github.com/sgrif/rails.git","ssh_url":"git@github.com:sgrif/rails.git","clone_url":"https://github.com/sgrif/rails.git","svn_url":"https://github.com/sgrif/rails","homepage":"http://rubyonrails.org","size":115879,"stargazers_count":0,"watchers_count":0,"language":"Ruby","has_issues":false,"has_downloads":true,"has_wiki":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"rails:master","ref":"master","sha":"70b931f846cb212f3db16f35a10094fb727a57e2","user":{"login":"rails","id":4223,"avatar_url":"https://avatars.githubusercontent.com/u/4223?","gravatar_id":"30f39a09e233e8369dddf6feb4be0308","url":"https://api.github.com/users/rails","html_url":"https://github.com/rails","followers_url":"https://api.github.com/users/rails/followers","following_url":"https://api.github.com/users/rails/following{/other_user}","gists_url":"https://api.github.com/users/rails/gists{/gist_id}","starred_url":"https://api.github.com/users/rails/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rails/subscriptions","organizations_url":"https://api.github.com/users/rails/orgs","repos_url":"https://api.github.com/users/rails/repos","events_url":"https://api.github.com/users/rails/events{/privacy}","received_events_url":"https://api.github.com/users/rails/received_events","type":"Organization","site_admin":false},"repo":{"id":8514,"name":"rails","full_name":"rails/rails","owner":{"login":"rails","id":4223,"avatar_url":"https://avatars.githubusercontent.com/u/4223?","gravatar_id":"30f39a09e233e8369dddf6feb4be0308","url":"https://api.github.com/users/rails","html_url":"https://github.com/rails","followers_url":"https://api.github.com/users/rails/followers","following_url":"https://api.github.com/users/rails/following{/other_user}","gists_url":"https://api.github.com/users/rails/gists{/gist_id}","starred_url":"https://api.github.com/users/rails/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rails/subscriptions","organizations_url":"https://api.github.com/users/rails/orgs","repos_url":"https://api.github.com/users/rails/repos","events_url":"https://api.github.com/users/rails/events{/privacy}","received_events_url":"https://api.github.com/users/rails/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/rails/rails","description":"Ruby on Rails","fork":false,"url":"https://api.github.com/repos/rails/rails","forks_url":"https://api.github.com/repos/rails/rails/forks","keys_url":"https://api.github.com/repos/rails/rails/keys{/key_id}","collaborators_url":"https://api.github.com/repos/rails/rails/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/rails/rails/teams","hooks_url":"https://api.github.com/repos/rails/rails/hooks","issue_events_url":"https://api.github.com/repos/rails/rails/issues/events{/number}","events_url":"https://api.github.com/repos/rails/rails/events","assignees_url":"https://api.github.com/repos/rails/rails/assignees{/user}","branches_url":"https://api.github.com/repos/rails/rails/branches{/branch}","tags_url":"https://api.github.com/repos/rails/rails/tags","blobs_url":"https://api.github.com/repos/rails/rails/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/rails/rails/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/rails/rails/git/refs{/sha}","trees_url":"https://api.github.com/repos/rails/rails/git/trees{/sha}","statuses_url":"https://api.github.com/repos/rails/rails/statuses/{sha}","languages_url":"https://api.github.com/repos/rails/rails/languages","stargazers_url":"https://api.github.com/repos/rails/rails/stargazers","contributors_url":"https://api.github.com/repos/rails/rails/contributors","subscribers_url":"https://api.github.com/repos/rails/rails/subscribers","subscription_url":"https://api.github.com/repos/rails/rails/subscription","commits_url":"https://api.github.com/repos/rails/rails/commits{/sha}","git_commits_url":"https://api.github.com/repos/rails/rails/git/commits{/sha}","comments_url":"https://api.github.com/repos/rails/rails/comments{/number}","issue_comment_url":"https://api.github.com/repos/rails/rails/issues/comments/{number}","contents_url":"https://api.github.com/repos/rails/rails/contents/{+path}","compare_url":"https://api.github.com/repos/rails/rails/compare/{base}...{head}","merges_url":"https://api.github.com/repos/rails/rails/merges","archive_url":"https://api.github.com/repos/rails/rails/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/rails/rails/downloads","issues_url":"https://api.github.com/repos/rails/rails/issues{/number}","pulls_url":"https://api.github.com/repos/rails/rails/pulls{/number}","milestones_url":"https://api.github.com/repos/rails/rails/milestones{/number}","notifications_url":"https://api.github.com/repos/rails/rails/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/rails/rails/labels{/name}","releases_url":"https://api.github.com/repos/rails/rails/releases{/id}","created_at":"2008-04-11T02:19:47Z","updated_at":"2014-06-13T13:54:30Z","pushed_at":"2014-06-13T13:54:30Z","git_url":"git://github.com/rails/rails.git","ssh_url":"git@github.com:rails/rails.git","clone_url":"https://github.com/rails/rails.git","svn_url":"https://github.com/rails/rails","homepage":"http://rubyonrails.org","size":319192,"stargazers_count":22141,"watchers_count":22141,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":false,"forks_count":8212,"mirror_url":null,"open_issues_count":619,"forks":8212,"open_issues":619,"watchers":22141,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/rails/rails/pulls/15593"},"html":{"href":"https://github.com/rails/rails/pull/15593"},"issue":{"href":"https://api.github.com/repos/rails/rails/issues/15593"},"comments":{"href":"https://api.github.com/repos/rails/rails/issues/15593/comments"},"review_comments":{"href":"https://api.github.com/repos/rails/rails/pulls/15593/comments"},"review_comment":{"href":"https://api.github.com/repos/rails/rails/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/rails/rails/pulls/15593/commits"},"statuses":{"href":"https://api.github.com/repos/rails/rails/statuses/f47414a82adaece6f39841a6e0d7093739b43596"}}}}