123456789_123456789_123456789_123456789_123456789_

Class: ActiveModel::AttributeSet::Builder::Context

Do not use. This class is for internal use only.
Relationships & Source Files
Extension / Inclusion / Inheritance Descendants
Subclasses:
Inherits: Object
Defined in: activemodel/lib/active_model/attribute_set/builder.rb

Overview

What a ::ActiveModel::LazyIndexedAttributeSet looks up about the model's attributes, by their index in the builder's #indexes.

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Constructor Details

.new(names, type_table, defaults) ⇒ Context

names are the attribute names by index, type_table their TypeTable, and defaults the default attributes by index that attributes a row doesn't have fall back to. : (Array, TypeTable, Array) -> void

[ GitHub ]

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

def initialize(names, type_table, defaults)
  @names = names
  @types = type_table.types
  @type_keys_lut = type_table.type_keys_lut
  @type_keys = type_table.type_keys
  @defaults = defaults
  freeze
end

Instance Attribute Details

#type_keys (readonly)

[ GitHub ]

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

attr_reader :type_keys

Instance Method Details

#default_at(index)

The default attribute for the attribute at index, if any. : (Integer) -> Attribute?

[ GitHub ]

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

def default_at(index)
  @defaults[index]
end

#name_at(index)

The name of the attribute at index. : (Integer) -> String?

[ GitHub ]

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

def name_at(index)
  @names[index]
end

#type_at(index, indexes)

The type of the attribute at index in a row laid out with ActiveModel::AttributeSet::Builder#indexes. Indexes after the model's are for names a row has that the model doesn't, typed by the query that selected them (see IndexedRow::ExtendedIndexes#type_at). : (Integer, Hash[String, Integer] | ::ActiveModel::IndexedRow::ExtendedIndexes) -> ::ActiveModel::Type::Value

[ GitHub ]

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

def type_at(index, indexes)
  if index < @types.size
    @types[index]
  elsif indexes.is_a?(IndexedRow::ExtendedIndexes)
    indexes.type_at(index) || Type.default_value
  else
    Type.default_value
  end
end

#type_key_at?(index) ⇒ Boolean

: (Integer) -> bool?

[ GitHub ]

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

def type_key_at?(index)
  @type_keys_lut[index]
end