Class: ActiveModel::IndexedRow::ExtendedIndexes
| Relationships & Source Files | |
| Inherits: | Object |
| Defined in: | activemodel/lib/active_model/indexed_row.rb |
Overview
Wraps an immutable column map and adds indexes for columns it doesn't have, such as aliases selected alongside a model's columns. The query that selected those columns can also say what type each one is.
Constant Summary
-
EMPTY_TYPES =
private
# File 'activemodel/lib/active_model/indexed_row.rb', line 268{}.freeze
Class Method Summary
- .add(indexes, column, index)
-
.new(indexes, extra, extra_types = EMPTY_TYPES) ⇒ ExtendedIndexes
constructor
#extra_types has the types of the #extra columns that have one, by slot.
Instance Attribute Summary
- #extra readonly
- #extra_types readonly
- #indexes readonly
Instance Method Summary
-
#==(other)
(also: #eql?)
: (untyped) -> bool.
-
#[](column)
: (String) -> Integer?
-
#each_key(&block)
: () ?{ (String) -> void } -> (self | Enumerator[String, self]).
-
#each_value(&block)
: () ?{ (Integer) -> void } -> (self | Enumerator[Integer, self]).
-
#eql?(other)
Alias for #==.
-
#fetch(column, &block)
: (String) ?{ (String) -> untyped } -> untyped.
-
#hash
: () ->
::Integer. -
#key?(column) ⇒ Boolean
: (String) -> bool.
-
#keys
: () -> Array.
-
#size
: () ->
::Integer. -
#type_at(slot)
The type of the extra column at
slot, if it has one.
Constructor Details
.new(indexes, extra, extra_types = EMPTY_TYPES) ⇒ ExtendedIndexes
#extra_types has the types of the #extra columns that have one, by slot. : (Hash[String, Integer], Hash[String, Integer], ?Hash[Integer, Type::Value]) -> void
# File 'activemodel/lib/active_model/indexed_row.rb', line 287
def initialize(indexes, extra, extra_types = EMPTY_TYPES) @indexes = indexes @extra = extra @extra_types = extra_types freeze end
Class Method Details
.add(indexes, column, index)
Instance Attribute Details
#extra (readonly)
[ GitHub ]# File 'activemodel/lib/active_model/indexed_row.rb', line 282
attr_reader :indexes, :extra, :extra_types
#extra_types (readonly)
[ GitHub ]#indexes (readonly)
[ GitHub ]# File 'activemodel/lib/active_model/indexed_row.rb', line 282
attr_reader :indexes, :extra, :extra_types
Instance Method Details
#==(other) Also known as: #eql?
: (untyped) -> bool
# File 'activemodel/lib/active_model/indexed_row.rb', line 344
def ==(other) other.is_a?(ExtendedIndexes) && @indexes == other.indexes && @extra == other.extra && @extra_types == other.extra_types end
#[](column)
: (String) -> Integer?
# File 'activemodel/lib/active_model/indexed_row.rb', line 301
def [](column) @indexes[column] || @extra[column] end
#each_key(&block)
: () ?{ (String) -> void } -> (self | Enumerator[String, self])
# File 'activemodel/lib/active_model/indexed_row.rb', line 316
def each_key(&block) return enum_for(:each_key) { size } unless block @indexes.each_key(&block) @extra.each_key(&block) self end
#each_value(&block)
: () ?{ (Integer) -> void } -> (self | Enumerator[Integer, self])
# File 'activemodel/lib/active_model/indexed_row.rb', line 330
def each_value(&block) return enum_for(:each_value) { size } unless block @indexes.each_value(&block) @extra.each_value(&block) self end
#eql?(other)
Alias for #==.
# File 'activemodel/lib/active_model/indexed_row.rb', line 348
alias_method :eql?, :==
#fetch(column, &block)
: (String) ?{ (String) -> untyped } -> untyped
# File 'activemodel/lib/active_model/indexed_row.rb', line 306
def fetch(column, &block) @indexes.fetch(column) { @extra.fetch(column, &block) } end
#hash
: () -> ::Integer
# File 'activemodel/lib/active_model/indexed_row.rb', line 351
def hash [ExtendedIndexes, @indexes, @extra, @extra_types].hash end
#key?(column) ⇒ Boolean
: (String) -> bool
# File 'activemodel/lib/active_model/indexed_row.rb', line 311
def key?(column) @indexes.key?(column) || @extra.key?(column) end
#keys
: () -> Array
# File 'activemodel/lib/active_model/indexed_row.rb', line 325
def keys @indexes.keys + @extra.keys end
#size
: () -> ::Integer
# File 'activemodel/lib/active_model/indexed_row.rb', line 339
def size @indexes.size + @extra.size end
#type_at(slot)
The type of the extra column at slot, if it has one.
: (Integer) -> Type::Value?
# File 'activemodel/lib/active_model/indexed_row.rb', line 296
def type_at(slot) @extra_types[slot] end