123456789_123456789_123456789_123456789_123456789_

Class: ActiveModel::LazyAttributeSet

Do not use. This class is for internal use only.
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

Instance Method Summary

AttributeSet - Inherited

#==,
#[]

: (String) -> Attribute

#[]=

: (String, Attribute) -> Attribute

#accessed, #cast_types,
#deep_dup

: () -> AttributeSet

#fetch_value,
#fetch_value!

Like #fetch_value, but raises MissingAttributeError if the attribute is uninitialized.

#fetch_value_at

Like #fetch_value, but looks the attribute up by its index in #indexes rather than by name.

#fetch_value_at!

Like #fetch_value!, but looks the attribute up by its index (see #fetch_value_at).

#freeze

: () -> self.

#include?
#indexes

: () -> (Hash[String, Integer] | IndexedRow::ExtendedIndexes).

#initialize_clone, #initialize_dup, #key?, #keys,
#map

: () { (ActiveModel::Attribute) -> Attribute } -> AttributeSet

#name_at

The name of the attribute at index.

#reset,
#to_h
#to_hash, #values, #values_before_type_cast, #values_for_database,
#write_cast_value

: (String, untyped) -> Attribute

#write_from_database

: (String, untyped) -> Attribute

#write_from_user

: (String, untyped) -> untyped.

#default_attribute,
#freeze_attributes

: () -> void.

#lookup

: (String) -> ActiveModel::Attribute?

#raise_unless_laid_out

Records marshaled in the ::Rails 6.1 format have their instance variables dumped directly.

#store

: (String, Attribute) -> Attribute

Constructor Details

This class inherits a constructor from ActiveModel::AttributeSet

Instance Method Details

#attributes (protected)

: () -> IndexedRow

[ GitHub ]

  
# 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

[ GitHub ]

  
# 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

[ GitHub ]

  
# 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

Raises:

[ GitHub ]

  
# File 'activemodel/lib/active_model/attribute_set.rb', line 632

def fetch_value_at(index)
  raise NotLaidOut
end

#fetch_value_at!(index)

: (Integer) -> bot

Raises:

[ GitHub ]

  
# File 'activemodel/lib/active_model/attribute_set.rb', line 637

def fetch_value_at!(index)
  raise NotLaidOut
end

#lookup(name) (private)

: (String) -> ActiveModel::Attribute?

[ GitHub ]

  
# File 'activemodel/lib/active_model/attribute_set.rb', line 650

def lookup(name)
  attributes[name]
end

#store(name, attribute) (private)

: (String, Attribute) -> Attribute

[ GitHub ]

  
# File 'activemodel/lib/active_model/attribute_set.rb', line 655

def store(name, attribute)
  attributes[name] = attribute
end