aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib
diff options
context:
space:
mode:
authorArthur Nogueira Neves <arthurnn@gmail.com>2015-02-10 17:26:30 -0500
committerArthur Nogueira Neves <arthurnn@gmail.com>2015-02-10 17:26:30 -0500
commit162581a448ac6f3e52901a90000336f394226381 (patch)
tree5641f0f632f3097495151af913476c794a2467cf /actionpack/lib
parent2c5c0690cc5fc324a1b61126dc81ee10e4bf2b29 (diff)
parent7a78c2512343203e854210d4ffed8a3142e1a4de (diff)
downloadrails-162581a448ac6f3e52901a90000336f394226381.tar.gz
rails-162581a448ac6f3e52901a90000336f394226381.tar.bz2
rails-162581a448ac6f3e52901a90000336f394226381.zip
Merge pull request #18872 from kaspth/kw-fresh_when-stale
Convert stale? and fresh_when to use keyword arguments.
Diffstat (limited to 'actionpack/lib')
-rw-r--r--actionpack/lib/action_controller/metal/conditional_get.rb22
1 files changed, 10 insertions, 12 deletions
diff --git a/actionpack/lib/action_controller/metal/conditional_get.rb b/actionpack/lib/action_controller/metal/conditional_get.rb
index febbc72861..bd7689a843 100644
--- a/actionpack/lib/action_controller/metal/conditional_get.rb
+++ b/actionpack/lib/action_controller/metal/conditional_get.rb
@@ -77,18 +77,16 @@ module ActionController
#
# before_action { fresh_when @article, template: 'widgets/show' }
#
- def fresh_when(record_or_options, additional_options = {})
- if record_or_options.is_a? Hash
- options = record_or_options
- options.assert_valid_keys(:etag, :last_modified, :public, :template)
- else
- record = record_or_options
- options = { etag: record, last_modified: record.try(:updated_at) }.merge!(additional_options)
+ def fresh_when(record = nil, etag: record, last_modified: nil, public: false, template: nil)
+ last_modified ||= record.try(:updated_at)
+
+ if etag || template
+ response.etag = combine_etags(etag: etag, last_modified: last_modified,
+ public: public, template: template)
end
- response.etag = combine_etags(options) if options[:etag] || options[:template]
- response.last_modified = options[:last_modified] if options[:last_modified]
- response.cache_control[:public] = true if options[:public]
+ response.last_modified = last_modified if last_modified
+ response.cache_control[:public] = true if public
head :not_modified if request.fresh?(response)
end
@@ -157,8 +155,8 @@ module ActionController
# super if stale? @article, template: 'widgets/show'
# end
#
- def stale?(record_or_options, additional_options = {})
- fresh_when(record_or_options, additional_options)
+ def stale?(record = nil, etag: nil, last_modified: nil, public: nil, template: nil)
+ fresh_when(record, etag: etag, last_modified: last_modified, public: public, template: template)
!request.fresh?(response)
end