Skip to content
Browse files

move include calculation to include method on the options object

  • Loading branch information...
1 parent 46284a1 commit 2a51d6c3bba3b295ad6696baeae351b359225c2e @tenderlove tenderlove committed Nov 13, 2012
Showing with 24 additions and 9 deletions.
  1. +24 −9 actionpack/lib/action_controller/metal/params_wrapper.rb
View
33 actionpack/lib/action_controller/metal/params_wrapper.rb
@@ -83,13 +83,36 @@ def self.from_hash(hash)
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 @@ def inherited(klass)
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 :

0 comments on commit 2a51d6c

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