From 2a51d6c3bba3b295ad6696baeae351b359225c2e Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Tue, 13 Nov 2012 14:26:22 -0800 Subject: move include calculation to include method on the options object --- .../lib/action_controller/metal/params_wrapper.rb | 33 ++++++++++++++++------ 1 file changed, 24 insertions(+), 9 deletions(-) (limited to 'actionpack/lib/action_controller/metal/params_wrapper.rb') 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 : -- cgit v1.2.3