diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2012-11-13 10:45:04 -0800 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2012-11-13 16:35:15 -0800 |
commit | bf3546549b5b355d4d03626a043cb110f628dd5b (patch) | |
tree | 1c3c3c8bbc3c659c674ba51b7ec6e9b39a044707 /actionpack/lib/action_controller/metal | |
parent | 9a64ffc0c77c2b614401fad665ae2edb33c754a7 (diff) | |
download | rails-bf3546549b5b355d4d03626a043cb110f628dd5b.tar.gz rails-bf3546549b5b355d4d03626a043cb110f628dd5b.tar.bz2 rails-bf3546549b5b355d4d03626a043cb110f628dd5b.zip |
only do hash lookups on options once
Diffstat (limited to 'actionpack/lib/action_controller/metal')
-rw-r--r-- | actionpack/lib/action_controller/metal/params_wrapper.rb | 28 |
1 files changed, 15 insertions, 13 deletions
diff --git a/actionpack/lib/action_controller/metal/params_wrapper.rb b/actionpack/lib/action_controller/metal/params_wrapper.rb index dedb80e408..f9f6cc27a3 100644 --- a/actionpack/lib/action_controller/metal/params_wrapper.rb +++ b/actionpack/lib/action_controller/metal/params_wrapper.rb @@ -119,7 +119,10 @@ module ActionController model = name_or_model_or_options end - _set_wrapper_defaults(_wrapper_options.slice(:format).merge(options), model) + opts = _wrapper_options.slice(:format).merge(options) + params = opts.values_at(:name, :format, :include, :exclude) + + _set_wrapper_defaults(*params, model) end # Sets the default wrapper key or model which will be used to determine @@ -127,7 +130,8 @@ module ActionController # module is inherited. def inherited(klass) if klass._wrapper_options[:format].any? - klass._set_wrapper_defaults(klass._wrapper_options.slice(:format)) + params = klass._wrapper_options.values_at(:name, :format, :include, :exclude) + klass._set_wrapper_defaults(*params) end super end @@ -159,27 +163,25 @@ module ActionController model_klass end - def _set_wrapper_defaults(options, model=nil) - options = options.dup - - unless options[:include] || options[:exclude] + def _set_wrapper_defaults(name, format, include, exclude, model=nil) + unless include || exclude model ||= _default_wrap_model if model.respond_to?(:attribute_names) && model.attribute_names.present? - options[:include] = model.attribute_names + include = model.attribute_names end end - unless options[:name] || self.anonymous? + unless name || self.anonymous? model ||= _default_wrap_model - options[:name] = model ? model.to_s.demodulize.underscore : + name = model ? model.to_s.demodulize.underscore : controller_name.singularize end - options[:include] = Array(options[:include]).collect(&:to_s) if options[:include] - options[:exclude] = Array(options[:exclude]).collect(&:to_s) if options[:exclude] - options[:format] = Array(options[:format]) + opts = { format: Array(format), name: name } + opts[:include] = Array(include).collect(&:to_s) if include + opts[:exclude] = Array(exclude).collect(&:to_s) if exclude - self._wrapper_options = options + self._wrapper_options = opts end end |