Class: ActiveModel::AttributeSet::Builder::Context
| 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
-
.new(names, type_table, defaults) ⇒ Context
constructor
namesare the attribute names by index,type_tabletheirTypeTable, anddefaultsthe default attributes by index that attributes a row doesn't have fall back to.
Instance Attribute Summary
- #type_keys readonly
Instance Method Summary
-
#default_at(index)
The default attribute for the attribute at
index, if any. -
#name_at(index)
The name of the attribute at
index. -
#type_at(index, indexes)
The type of the attribute at
indexin a row laid out with #indexes. -
#type_key_at?(index) ⇒ Boolean
: (Integer) -> bool?
Constructor Details
.new(names, type_table, defaults) ⇒ Context
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?
# 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?
# 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
# 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?
# File 'activemodel/lib/active_model/attribute_set/builder.rb', line 39
def type_key_at?(index) @type_keys_lut[index] end