123456789_123456789_123456789_123456789_123456789_

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

Class Method Summary

Instance Attribute Summary

Instance Method Summary

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

[ GitHub ]

  
# 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)

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

[ GitHub ]

  
# 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

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 ]

  
# File 'activemodel/lib/active_model/indexed_row.rb', line 282

attr_reader :indexes, :extra, :extra_types

#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

[ GitHub ]

  
# 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?

[ GitHub ]

  
# 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])

[ GitHub ]

  
# 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])

[ GitHub ]

  
# 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 #==.

[ GitHub ]

  
# File 'activemodel/lib/active_model/indexed_row.rb', line 348

alias_method :eql?, :==

#fetch(column, &block)

: (String) ?{ (String) -> untyped } -> untyped

[ GitHub ]

  
# File 'activemodel/lib/active_model/indexed_row.rb', line 306

def fetch(column, &block)
  @indexes.fetch(column) { @extra.fetch(column, &block) }
end

#hash

: () -> ::Integer

[ GitHub ]

  
# File 'activemodel/lib/active_model/indexed_row.rb', line 351

def hash
  [ExtendedIndexes, @indexes, @extra, @extra_types].hash
end

#key?(column) ⇒ Boolean

: (String) -> bool

[ GitHub ]

  
# File 'activemodel/lib/active_model/indexed_row.rb', line 311

def key?(column)
  @indexes.key?(column) || @extra.key?(column)
end

#keys

: () -> Array

[ GitHub ]

  
# File 'activemodel/lib/active_model/indexed_row.rb', line 325

def keys
  @indexes.keys + @extra.keys
end

#size

: () -> ::Integer

[ GitHub ]

  
# 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?

[ GitHub ]

  
# File 'activemodel/lib/active_model/indexed_row.rb', line 296

def type_at(slot)
  @extra_types[slot]
end