aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_controller/metal/params_wrapper.rb
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2012-11-13 13:17:41 -0800
committerAaron Patterson <aaron.patterson@gmail.com>2012-11-13 16:35:15 -0800
commitfc29bff445a4845fcbcbbb96f071a49bc0258684 (patch)
treeaaa12ab865ffc5af6f5622f1c307095b0ae3a2bc /actionpack/lib/action_controller/metal/params_wrapper.rb
parent95ec44858023d7263a2227effc064d5b8a22b772 (diff)
downloadrails-fc29bff445a4845fcbcbbb96f071a49bc0258684.tar.gz
rails-fc29bff445a4845fcbcbbb96f071a49bc0258684.tar.bz2
rails-fc29bff445a4845fcbcbbb96f071a49bc0258684.zip
use the options object in the wrapper defaults
Diffstat (limited to 'actionpack/lib/action_controller/metal/params_wrapper.rb')
-rw-r--r--actionpack/lib/action_controller/metal/params_wrapper.rb25
1 files changed, 12 insertions, 13 deletions
diff --git a/actionpack/lib/action_controller/metal/params_wrapper.rb b/actionpack/lib/action_controller/metal/params_wrapper.rb
index 0a463257ce..3230c6d1b7 100644
--- a/actionpack/lib/action_controller/metal/params_wrapper.rb
+++ b/actionpack/lib/action_controller/metal/params_wrapper.rb
@@ -131,9 +131,8 @@ module ActionController
end
opts = _wrapper_options.to_h.slice(:format).merge(options)
- params = opts.values_at(:name, :format, :include, :exclude)
- _set_wrapper_defaults(*params, model)
+ _set_wrapper_defaults(Options.from_hash(opts), model)
end
# Sets the default wrapper key or model which will be used to determine
@@ -141,8 +140,8 @@ module ActionController
# module is inherited.
def inherited(klass)
if klass._wrapper_options.format.any?
- params = klass._wrapper_options.to_h.values_at(:name, :format, :include, :exclude)
- klass._set_wrapper_defaults(*params)
+ params = klass._wrapper_options
+ klass._set_wrapper_defaults(params.dup)
end
super
end
@@ -174,25 +173,25 @@ module ActionController
model_klass
end
- def _set_wrapper_defaults(name, format, include, exclude, model=nil)
- unless include || exclude
+ def _set_wrapper_defaults(opts, model=nil)
+ unless opts.include || opts.exclude
model ||= _default_wrap_model
if model.respond_to?(:attribute_names) && model.attribute_names.present?
- include = model.attribute_names
+ opts.include = model.attribute_names
end
end
- unless name || self.anonymous?
+ unless opts.name || self.anonymous?
model ||= _default_wrap_model
- name = model ? model.to_s.demodulize.underscore :
+ opts.name = model ? model.to_s.demodulize.underscore :
controller_name.singularize
end
- opts = { format: Array(format), name: name }
- opts[:include] = Array(include).collect(&:to_s) if include
- opts[:exclude] = Array(exclude).collect(&:to_s) if exclude
+ opts.format = Array(opts.format)
+ opts.include &&= Array(opts.include).collect(&:to_s)
+ opts.exclude &&= Array(opts.exclude).collect(&:to_s)
- self._wrapper_options = Options.from_hash(opts)
+ self._wrapper_options = opts
end
end