diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2012-11-13 14:26:22 -0800 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2012-11-13 16:35:16 -0800 |
commit | 2a51d6c3bba3b295ad6696baeae351b359225c2e (patch) | |
tree | 42db9bfb076469a74e40443389c4a7a0475e158d /actionpack/lib/action_controller/metal | |
parent | 46284a183e4c5a96f43542d26e86194c47347d2a (diff) | |
download | rails-2a51d6c3bba3b295ad6696baeae351b359225c2e.tar.gz rails-2a51d6c3bba3b295ad6696baeae351b359225c2e.tar.bz2 rails-2a51d6c3bba3b295ad6696baeae351b359225c2e.zip |
move include calculation to include method on the options object
Diffstat (limited to 'actionpack/lib/action_controller/metal')
-rw-r--r-- | actionpack/lib/action_controller/metal/params_wrapper.rb | 33 |
1 files changed, 24 insertions, 9 deletions
diff --git a/actionpack/lib/action_controller/metal/params_wrapper.rb b/actionpack/lib/action_controller/metal/params_wrapper.rb index 9dc7469bd7..c5dbe6b45e 100644 --- a/actionpack/lib/action_controller/metal/params_wrapper.rb +++ b/actionpack/lib/action_controller/metal/params_wrapper.rb @@ -83,13 +83,36 @@ module ActionController format = Array(hash[:format]) include = hash[:include] && Array(hash[:include]).collect(&:to_s) exclude = hash[:exclude] && Array(hash[:exclude]).collect(&:to_s) - new name, format, include, exclude + new name, format, include, exclude, nil, nil + end + + def initialize(name, format, include, exclude, klass, model) # nodoc + super + @include_set = include + @name_set = name end def model super || synchronize { super || self.model = _default_wrap_model } end + def include + return super if @include_set + + m = model + synchronize do + return super if @include_set + + @include_set = true + + unless super || exclude + if m.respond_to?(:attribute_names) && m.attribute_names.any? + self.include = m.attribute_names + end + end + end + end + private # Determine the wrapper model from the controller's name. By convention, # this could be done by trying to find the defined model that has the @@ -189,15 +212,7 @@ module ActionController protected - def _set_wrapper_defaults(opts) - unless opts.include || opts.exclude - model = opts.model - if model.respond_to?(:attribute_names) && model.attribute_names.any? - opts.include = model.attribute_names - end - end - unless opts.name || opts.klass.anonymous? model = opts.model opts.name = model ? model.to_s.demodulize.underscore : |