Skip to Content Skip to Search

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.

Methods
#
A
E
F
H
K
N
S
T

Attributes

[R] extra
[R] extra_types
[R] indexes

Class Public methods

add(indexes, column, index)

Returns indexes with column added at index, without modifying indexes. : (Hash[String, Integer] | ExtendedIndexes, String, Integer) -> ExtendedIndexes

# File activemodel/lib/active_model/indexed_row.rb, line 274
def self.add(indexes, column, index)
  if indexes.is_a?(self)
    new(indexes.indexes, indexes.extra.merge(column => index).freeze, indexes.extra_types)
  else
    new(indexes, { column => index }.freeze)
  end
end

new(indexes, extra, extra_types = EMPTY_TYPES)

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

Instance Public methods

==(other)

: (untyped) -> bool

Also aliased as: eql?
# 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: ==

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)

: (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