{"action":"opened","number":18374,"pull_request":{"url":"https://api.github.com/repos/rails/rails/pulls/18374","id":26928982,"html_url":"https://github.com/rails/rails/pull/18374","diff_url":"https://github.com/rails/rails/pull/18374.diff","patch_url":"https://github.com/rails/rails/pull/18374.patch","issue_url":"https://api.github.com/repos/rails/rails/issues/18374","number":18374,"state":"open","locked":false,"title":"Accept a collection in fresh_when and stale?","user":{"login":"claudiob","id":10076,"avatar_url":"https://avatars.githubusercontent.com/u/10076?v=3","gravatar_id":"","url":"https://api.github.com/users/claudiob","html_url":"https://github.com/claudiob","followers_url":"https://api.github.com/users/claudiob/followers","following_url":"https://api.github.com/users/claudiob/following{/other_user}","gists_url":"https://api.github.com/users/claudiob/gists{/gist_id}","starred_url":"https://api.github.com/users/claudiob/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/claudiob/subscriptions","organizations_url":"https://api.github.com/users/claudiob/orgs","repos_url":"https://api.github.com/users/claudiob/repos","events_url":"https://api.github.com/users/claudiob/events{/privacy}","received_events_url":"https://api.github.com/users/claudiob/received_events","type":"User","site_admin":false},"body":"The methods `fresh_when` and `stale?` from `ActionController::ConditionalGet` accept a single record as a short form for a hash ([see docs](http://api.rubyonrails.org/classes/ActionController/ConditionalGet.html)). For instance:\r\n\r\n```ruby\r\n  def show\r\n    @article = Article.find(params[:id])\r\n    fresh_when(@article)\r\n  end\r\n```\r\n\r\nis just a short form for:\r\n\r\n```ruby\r\n  def show\r\n    @article = Article.find(params[:id])\r\n    fresh_when(etag: @article, last_modified: @article.created_at)\r\n  end\r\n```\r\n\r\nThis commit extends `fresh_when` and `stale?` to also accept a collection of records, so that a short form similar to the one above can be used in an `index` action. \r\nAfter this commit, the following code:\r\n\r\n```ruby\r\ndef index\r\n  @article = Article.all\r\n  fresh_when(etag: @articles, last_modified: @articles.maximum(:created_at))\r\nend\r\n```\r\n\r\ncan be simply written as:\r\n\r\n```ruby\r\ndef index\r\n  @article = Article.all\r\n  fresh_when(@articles)\r\nend\r\n```","created_at":"2015-01-07T00:16:36Z","updated_at":"2015-01-07T00:16:36Z","closed_at":null,"merged_at":null,"merge_commit_sha":null,"assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/rails/rails/pulls/18374/commits","review_comments_url":"https://api.github.com/repos/rails/rails/pulls/18374/comments","review_comment_url":"https://api.github.com/repos/rails/rails/pulls/comments/{number}","comments_url":"https://api.github.com/repos/rails/rails/issues/18374/comments","statuses_url":"https://api.github.com/repos/rails/rails/statuses/b7ae48511123d6b6df70cb57e1880649c467e70f","head":{"label":"claudiob:add-collection-to-fresh-when","ref":"add-collection-to-fresh-when","sha":"b7ae48511123d6b6df70cb57e1880649c467e70f","user":{"login":"claudiob","id":10076,"avatar_url":"https://avatars.githubusercontent.com/u/10076?v=3","gravatar_id":"","url":"https://api.github.com/users/claudiob","html_url":"https://github.com/claudiob","followers_url":"https://api.github.com/users/claudiob/followers","following_url":"https://api.github.com/users/claudiob/following{/other_user}","gists_url":"https://api.github.com/users/claudiob/gists{/gist_id}","starred_url":"https://api.github.com/users/claudiob/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/claudiob/subscriptions","organizations_url":"https://api.github.com/users/claudiob/orgs","repos_url":"https://api.github.com/users/claudiob/repos","events_url":"https://api.github.com/users/claudiob/events{/privacy}","received_events_url":"https://api.github.com/users/claudiob/received_events","type":"User","site_admin":false},"repo":{"id":3272669,"name":"rails","full_name":"claudiob/rails","owner":{"login":"claudiob","id":10076,"avatar_url":"https://avatars.githubusercontent.com/u/10076?v=3","gravatar_id":"","url":"https://api.github.com/users/claudiob","html_url":"https://github.com/claudiob","followers_url":"https://api.github.com/users/claudiob/followers","following_url":"https://api.github.com/users/claudiob/following{/other_user}","gists_url":"https://api.github.com/users/claudiob/gists{/gist_id}","starred_url":"https://api.github.com/users/claudiob/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/claudiob/subscriptions","organizations_url":"https://api.github.com/users/claudiob/orgs","repos_url":"https://api.github.com/users/claudiob/repos","events_url":"https://api.github.com/users/claudiob/events{/privacy}","received_events_url":"https://api.github.com/users/claudiob/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/claudiob/rails","description":"Ruby on Rails","fork":true,"url":"https://api.github.com/repos/claudiob/rails","forks_url":"https://api.github.com/repos/claudiob/rails/forks","keys_url":"https://api.github.com/repos/claudiob/rails/keys{/key_id}","collaborators_url":"https://api.github.com/repos/claudiob/rails/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/claudiob/rails/teams","hooks_url":"https://api.github.com/repos/claudiob/rails/hooks","issue_events_url":"https://api.github.com/repos/claudiob/rails/issues/events{/number}","events_url":"https://api.github.com/repos/claudiob/rails/events","assignees_url":"https://api.github.com/repos/claudiob/rails/assignees{/user}","branches_url":"https://api.github.com/repos/claudiob/rails/branches{/branch}","tags_url":"https://api.github.com/repos/claudiob/rails/tags","blobs_url":"https://api.github.com/repos/claudiob/rails/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/claudiob/rails/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/claudiob/rails/git/refs{/sha}","trees_url":"https://api.github.com/repos/claudiob/rails/git/trees{/sha}","statuses_url":"https://api.github.com/repos/claudiob/rails/statuses/{sha}","languages_url":"https://api.github.com/repos/claudiob/rails/languages","stargazers_url":"https://api.github.com/repos/claudiob/rails/stargazers","contributors_url":"https://api.github.com/repos/claudiob/rails/contributors","subscribers_url":"https://api.github.com/repos/claudiob/rails/subscribers","subscription_url":"https://api.github.com/repos/claudiob/rails/subscription","commits_url":"https://api.github.com/repos/claudiob/rails/commits{/sha}","git_commits_url":"https://api.github.com/repos/claudiob/rails/git/commits{/sha}","comments_url":"https://api.github.com/repos/claudiob/rails/comments{/number}","issue_comment_url":"https://api.github.com/repos/claudiob/rails/issues/comments/{number}","contents_url":"https://api.github.com/repos/claudiob/rails/contents/{+path}","compare_url":"https://api.github.com/repos/claudiob/rails/compare/{base}...{head}","merges_url":"https://api.github.com/repos/claudiob/rails/merges","archive_url":"https://api.github.com/repos/claudiob/rails/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/claudiob/rails/downloads","issues_url":"https://api.github.com/repos/claudiob/rails/issues{/number}","pulls_url":"https://api.github.com/repos/claudiob/rails/pulls{/number}","milestones_url":"https://api.github.com/repos/claudiob/rails/milestones{/number}","notifications_url":"https://api.github.com/repos/claudiob/rails/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/claudiob/rails/labels{/name}","releases_url":"https://api.github.com/repos/claudiob/rails/releases{/id}","created_at":"2012-01-26T09:52:30Z","updated_at":"2014-11-20T19:18:52Z","pushed_at":"2015-01-06T23:51:55Z","git_url":"git://github.com/claudiob/rails.git","ssh_url":"git@github.com:claudiob/rails.git","clone_url":"https://github.com/claudiob/rails.git","svn_url":"https://github.com/claudiob/rails","homepage":"http://rubyonrails.org","size":123832,"stargazers_count":1,"watchers_count":1,"language":"Ruby","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":1,"default_branch":"master"}},"base":{"label":"rails:master","ref":"master","sha":"5d28c6b5b8407abf9274f78502d387c98f209286","user":{"login":"rails","id":4223,"avatar_url":"https://avatars.githubusercontent.com/u/4223?v=3","gravatar_id":"","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?v=3","gravatar_id":"","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":"2015-01-06T22:41:19Z","pushed_at":"2015-01-06T22:41:19Z","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":372658,"stargazers_count":24501,"watchers_count":24501,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":9443,"mirror_url":null,"open_issues_count":714,"forks":9443,"open_issues":714,"watchers":24501,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/rails/rails/pulls/18374"},"html":{"href":"https://github.com/rails/rails/pull/18374"},"issue":{"href":"https://api.github.com/repos/rails/rails/issues/18374"},"comments":{"href":"https://api.github.com/repos/rails/rails/issues/18374/comments"},"review_comments":{"href":"https://api.github.com/repos/rails/rails/pulls/18374/comments"},"review_comment":{"href":"https://api.github.com/repos/rails/rails/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/rails/rails/pulls/18374/commits"},"statuses":{"href":"https://api.github.com/repos/rails/rails/statuses/b7ae48511123d6b6df70cb57e1880649c467e70f"}},"merged":false,"mergeable":null,"mergeable_state":"unknown","merged_by":null,"comments":0,"review_comments":0,"commits":1,"additions":101,"deletions":13,"changed_files":2}}