diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2012-11-13 13:46:06 -0800 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2012-11-13 16:35:15 -0800 |
commit | d7c72706007151a4a140a6c9af4547843bf7a9df (patch) | |
tree | a3baa2315dde1c7b33ad56d4f09464100c0055b3 | |
parent | 4729208f6a89b4d98b9a1049175297775a9e0f33 (diff) | |
download | rails-d7c72706007151a4a140a6c9af4547843bf7a9df.tar.gz rails-d7c72706007151a4a140a6c9af4547843bf7a9df.tar.bz2 rails-d7c72706007151a4a140a6c9af4547843bf7a9df.zip |
move the controller class to the options object
-rw-r--r-- | actionpack/lib/action_controller/metal/params_wrapper.rb | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/actionpack/lib/action_controller/metal/params_wrapper.rb b/actionpack/lib/action_controller/metal/params_wrapper.rb index 42519488bd..65ed7ce7fd 100644 --- a/actionpack/lib/action_controller/metal/params_wrapper.rb +++ b/actionpack/lib/action_controller/metal/params_wrapper.rb @@ -73,7 +73,7 @@ module ActionController EXCLUDE_PARAMETERS = %w(authenticity_token _method utf8) - Options = Struct.new(:name, :format, :include, :exclude) do # :nodoc: + Options = Struct.new(:name, :format, :include, :exclude, :klass, :model) do # :nodoc: def self.from_hash(hash) name = hash[:name] format = Array(hash[:format]) @@ -134,9 +134,11 @@ module ActionController model = name_or_model_or_options end - opts = _wrapper_options.to_h.slice(:format).merge(options) + opts = Options.from_hash _wrapper_options.to_h.slice(:format).merge(options) + opts.model = model + opts.klass = self - _set_wrapper_defaults(Options.from_hash(opts), model) + _set_wrapper_defaults(opts) end # Sets the default wrapper key or model which will be used to determine @@ -144,8 +146,9 @@ module ActionController # module is inherited. def inherited(klass) if klass._wrapper_options.format.any? - params = klass._wrapper_options - klass._set_wrapper_defaults(params.dup) + params = klass._wrapper_options.dup + params.klass = klass + klass._set_wrapper_defaults(params) end super end @@ -177,16 +180,16 @@ module ActionController model_klass end - def _set_wrapper_defaults(opts, model=nil) + def _set_wrapper_defaults(opts) unless opts.include || opts.exclude - model ||= _default_wrap_model + model = (opts.model ||= _default_wrap_model) if model.respond_to?(:attribute_names) && model.attribute_names.any? opts.include = model.attribute_names end end - unless opts.name || self.anonymous? - model ||= _default_wrap_model + unless opts.name || opts.klass.anonymous? + model = (opts.model ||= _default_wrap_model) opts.name = model ? model.to_s.demodulize.underscore : controller_name.singularize end |