diff options
author | Kasper Timm Hansen <kaspth@gmail.com> | 2015-02-10 14:46:45 +0100 |
---|---|---|
committer | Kasper Timm Hansen <kaspth@gmail.com> | 2015-02-10 23:01:47 +0100 |
commit | 7a78c2512343203e854210d4ffed8a3142e1a4de (patch) | |
tree | 4265c2249772c6a2fe65221c14d11f3a39cd9622 /actionpack | |
parent | a2c80a894578ef0eee0da6a97ae2660aea69d12f (diff) | |
download | rails-7a78c2512343203e854210d4ffed8a3142e1a4de.tar.gz rails-7a78c2512343203e854210d4ffed8a3142e1a4de.tar.bz2 rails-7a78c2512343203e854210d4ffed8a3142e1a4de.zip |
Convert stale? and fresh_when to use keyword arguments.
Diffstat (limited to 'actionpack')
-rw-r--r-- | actionpack/lib/action_controller/metal/conditional_get.rb | 22 |
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 |