123456789_123456789_123456789_123456789_123456789_

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

Instance Method Summary

::Struct - Inherited

Constructor Details

.new(name, format, include, exclude, klass, model) ⇒ Options

[ GitHub ]

  
# File 'actionpack/lib/action_controller/metal/params_wrapper.rb', line 97

def initialize(name, format, include, exclude, klass, model) # :nodoc:
  super
  @mutex = Mutex.new
  @include_set = include
  @name_set    = name
end

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 ]

  
# File 'actionpack/lib/action_controller/metal/params_wrapper.rb', line 88

class Options < Struct.new(:name, :format, :include, :exclude, :klass, :model)

#format (rw)

[ GitHub ]

  
# File 'actionpack/lib/action_controller/metal/params_wrapper.rb', line 88

class Options < Struct.new(:name, :format, :include, :exclude, :klass, :model)

#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?(: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

#include=(value) (rw)

[ GitHub ]

  
# File 'actionpack/lib/action_controller/metal/params_wrapper.rb', line 88

class Options < Struct.new(:name, :format, :include, :exclude, :klass, :model)

#klass (rw)

[ GitHub ]

  
# File 'actionpack/lib/action_controller/metal/params_wrapper.rb', line 88

class Options < Struct.new(:name, :format, :include, :exclude, :klass, :model)

#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 ]

  
# File 'actionpack/lib/action_controller/metal/params_wrapper.rb', line 88

class Options < Struct.new(:name, :format, :include, :exclude, :klass, :model)

#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 ]

  
# File 'actionpack/lib/action_controller/metal/params_wrapper.rb', line 88

class Options < Struct.new(:name, :format, :include, :exclude, :klass, :model)

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.

[ GitHub ]

  
# 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