1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

move include calculation to include method on the options object

This commit is contained in:
Aaron Patterson 2012-11-13 14:26:22 -08:00
parent 46284a183e
commit 2a51d6c3bb

View file

@ -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 :