Class: ActiveModel::LazyAttributeSet
| Relationships & Source Files | |
| Namespace Children | |
|
Exceptions:
| |
| Super Chains via Extension / Inclusion / Inheritance | |
|
Class Chain:
self,
AttributeSet
|
|
|
Instance Chain:
self,
AttributeSet
|
|
| Inherits: |
ActiveModel::AttributeSet
|
| Defined in: | activemodel/lib/active_model/attribute_set.rb |
Overview
Records marshaled in the ::Rails 6.1 format have their instance variables
dumped directly, so their attribute sets load as this class (the name
of the lazy attribute set at the time), with their attributes in Hashes
by name. The first use builds every attribute and then works by name,
like an AttributeSet. Its layout isn't the model's, so it can't be read
by slot: the record lays it out like the model's first (see
ActiveRecord::AttributeMethods::Read#_read_attribute_at!).
Class Method Summary
AttributeSet - Inherited
Instance Attribute Summary
AttributeSet - Inherited
Instance Method Summary
-
#fetch_value_at(index)
: (Integer) -> bot.
-
#fetch_value_at!(index)
: (Integer) -> bot.
-
#attributes
protected
: () ->
IndexedRow -
#build_attribute(name)
private
: (String) ->
Attribute -
#build_attributes
private
@valuesand@casted_valuesare Hashes, or IndexedRows in dumps from later versions, so they're only read through methods both have. -
#lookup(name)
private
: (String) ->
ActiveModel::Attribute? - #store(name, attribute) private
AttributeSet - Inherited
| #==, | |
| #[] | : (String) -> |
| #[]= | |
| #accessed, #cast_types, | |
| #deep_dup | : () -> |
| #fetch_value, | |
| #fetch_value! | Like |
| #fetch_value_at | Like |
| #fetch_value_at! | Like |
| #freeze | : () -> self. |
| #include? | Alias for AttributeSet#key?. |
| #indexes | : () -> (Hash[String, Integer] | |
| #initialize_clone, #initialize_dup, #key?, #keys, | |
| #map | : () { (ActiveModel::Attribute) -> |
| #name_at | The name of the attribute at |
| #reset, | |
| #to_h | Alias for AttributeSet#to_hash. |
| #to_hash, #values, #values_before_type_cast, #values_for_database, | |
| #write_cast_value | : (String, untyped) -> |
| #write_from_database | : (String, untyped) -> |
| #write_from_user | : (String, untyped) -> untyped. |
| #default_attribute, | |
| #freeze_attributes | : () -> void. |
| #lookup | : (String) -> |
| #raise_unless_laid_out | Records marshaled in the |
| #store | |
Constructor Details
This class inherits a constructor from ActiveModel::AttributeSet
Instance Method Details
#attributes (protected)
: () -> IndexedRow
# File 'activemodel/lib/active_model/attribute_set.rb', line 643
def attributes build_attributes if @attributes.is_a?(Hash) @attributes end
#build_attribute(name) (private)
: (String) -> Attribute
# File 'activemodel/lib/active_model/attribute_set.rb', line 670
def build_attribute(name) type = @additional_types.fetch(name) { @types[name] } || Type.default_value if @values.key?(name) Attribute.from_database(name, @values[name], type, @casted_values.fetch(name) { nil }) else default_keys = @default_keys if defined?(@default_keys) if (default_keys.nil? || default_keys.include?(name)) && (attr = @default_attributes.fetch(name) { nil }) attr.dup else Attribute.uninitialized(name, type) end end end
#build_attributes (private)
@values and @casted_values are Hashes, or IndexedRows in dumps
from later versions, so they're only read through methods both have.
: () -> IndexedRow::Mutable
# File 'activemodel/lib/active_model/attribute_set.rb', line 662
def build_attributes built = @attributes names = @values.keys | @types.keys | built.keys attributes = names.index_with { |name| built[name] || build_attribute(name) } @attributes = IndexedRow::Mutable[attributes] end
#fetch_value_at(index)
: (Integer) -> bot
# File 'activemodel/lib/active_model/attribute_set.rb', line 632
def fetch_value_at(index) raise NotLaidOut end
#fetch_value_at!(index)
: (Integer) -> bot
# File 'activemodel/lib/active_model/attribute_set.rb', line 637
def fetch_value_at!(index) raise NotLaidOut end
#lookup(name) (private)
: (String) -> ActiveModel::Attribute?
# File 'activemodel/lib/active_model/attribute_set.rb', line 650
def lookup(name) attributes[name] end
#store(name, attribute) (private)
[ GitHub ]# File 'activemodel/lib/active_model/attribute_set.rb', line 655
def store(name, attribute) attributes[name] = attribute end