Skip to content
Browse files

use the options object in the wrapper defaults

  • Loading branch information...
1 parent 95ec448 commit fc29bff445a4845fcbcbbb96f071a49bc0258684 @tenderlove tenderlove committed Nov 13, 2012
Showing with 12 additions and 13 deletions.
  1. +12 −13 actionpack/lib/action_controller/metal/params_wrapper.rb
View
25 actionpack/lib/action_controller/metal/params_wrapper.rb
@@ -131,18 +131,17 @@ def wrap_parameters(name_or_model_or_options, options = {})
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
# wrapper key and attribute names. Will be called automatically when the
# 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 @@ def _default_wrap_model #:nodoc:
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

0 comments on commit fc29bff

Please sign in to comment.
Something went wrong with that request. Please try again.