class ActionController::ParamsWrapper::Options
:nodoc:
def self.from_hash(hash)
def self.from_hash(hash) name = hash[:name] 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, nil, nil end
def _default_wrap_model #:nodoc:
try to find Foo::Bar::User, Foo::User and finally User.
This method also does namespace lookup. Foo::Bar::UsersController will
will try to find if the +User+ model exists.
same singular name as the controller. For example, +UsersController+
this could be done by trying to find the defined model that has the
Determine the wrapper model from the controller's name. By convention,
def _default_wrap_model #:nodoc: return nil if klass.anonymous? model_name = klass.name.sub(/Controller$/, '').classify begin if model_klass = model_name.safe_constantize model_klass else namespaces = model_name.split("::") namespaces.delete_at(-2) break if namespaces.last == model_name model_name = namespaces.join("::") end end until model_klass model_klass end
def include
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
def initialize(name, format, include, exclude, klass, model) # :nodoc:
def initialize(name, format, include, exclude, klass, model) # :nodoc: super @include_set = include @name_set = name end
def model
def model super || synchronize { super || self.model = _default_wrap_model } end
def name
def name return super if @name_set m = model synchronize do return super if @name_set @name_set = true unless super || klass.anonymous? self.name = m ? m.to_s.demodulize.underscore : klass.controller_name.singularize end end end