Class: ActionController::ParamsWrapper::Options
Do not use. This class is for internal use only.
Relationships & Source Files | |
Super Chains via Extension / Inclusion / Inheritance | |
Class Chain:
self,
::Struct
|
|
Instance Chain:
self,
::Struct
|
|
Inherits: | Struct |
Defined in: | actionpack/lib/action_controller/metal/params_wrapper.rb |
Class Method Summary
Instance Attribute Summary
- #exclude rw
- #format rw
- #include rw
- #include=(value) rw
- #klass rw
- #model rw
- #model=(value) rw
- #name rw
- #name=(value) rw
Instance Method Summary
-
#_default_wrap_model
private
Determine the wrapper model from the controller’s name.
::Struct
- Inherited
Constructor Details
.new(name, format, include, exclude, klass, model) ⇒ Options
Class Method Details
.from_hash(hash)
[ GitHub ]# File 'actionpack/lib/action_controller/metal/params_wrapper.rb', line 89
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
Instance Attribute Details
#exclude (rw)
[ GitHub ]#format (rw)
[ GitHub ]#include (rw)
[ GitHub ]# File 'actionpack/lib/action_controller/metal/params_wrapper.rb', line 108
def include return super if @include_set m = model @mutex.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?(: ) && m. .keys.any? self.include += m. .keys.map do |key| (+key.to_s).concat("_attributes") end end self.include end end end end
#include=(value) (rw)
[ GitHub ]#klass (rw)
[ GitHub ]#model (rw)
[ GitHub ]# File 'actionpack/lib/action_controller/metal/params_wrapper.rb', line 104
def model super || self.model = _default_wrap_model end
#model=(value) (rw)
[ GitHub ]#name (rw)
[ GitHub ]# File 'actionpack/lib/action_controller/metal/params_wrapper.rb', line 141
def name return super if @name_set m = model @mutex.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
#name=(value) (rw)
[ GitHub ]Instance Method Details
#_default_wrap_model (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 same singular name as the controller. For example, UsersController
will try to find if the User
model exists.
This method also does namespace lookup. Foo::Bar::UsersController
will try to find Foo::Bar::User
, Foo::User
and finally User.
# File 'actionpack/lib/action_controller/metal/params_wrapper.rb', line 165
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