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
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 return nil if klass.anonymous? model_name = klass.name.delete_suffix("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 if m.respond_to?(:stored_attributes) && !m.stored_attributes.empty? self.include += m.stored_attributes.values.flatten.map(&:to_s) end if m.respond_to?(:attribute_aliases) && m.attribute_aliases.any? self.include += m.attribute_aliases.keys end if m.respond_to?(:nested_attributes_options) && m.nested_attributes_options.keys.any? self.include += m.nested_attributes_options.keys.map do |key| (+key.to_s).concat("_attributes") end end self.include 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 || 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