Class: AlgebraDB::Build::SelectList::RowDecoder

Inherits:
Exec::RowDecoder show all
Defined in:
lib/algebra_db/build/select_list.rb

Overview

Row decoder that delegates to the decoders of the items in the select list.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(columns) ⇒ RowDecoder

rubocop:disable Lint/MissingSuper



26
27
28
29
# File 'lib/algebra_db/build/select_list.rb', line 26

def initialize(columns) # rubocop:disable Lint/MissingSuper
  @columns = columns
  @column_decoders = columns.map(&:decoder)
end

Instance Attribute Details

#column_decodersObject (readonly)

Returns the value of attribute column_decoders.



31
32
33
# File 'lib/algebra_db/build/select_list.rb', line 31

def column_decoders
  @column_decoders
end

Instance Method Details

#decode_row(row) ⇒ Object



37
38
39
40
41
42
# File 'lib/algebra_db/build/select_list.rb', line 37

def decode_row(row)
  values = row.values.map.with_index do |r, i|
    @column_decoders[i].decode_value(r)
  end
  row_struct.new(*values)
end

#pg_type_mapObject



33
34
35
# File 'lib/algebra_db/build/select_list.rb', line 33

def pg_type_map
  PG::TypeMapByColumn.new(column_decoders.map(&:pg_decoder))
end

#row_structObject



44
45
46
# File 'lib/algebra_db/build/select_list.rb', line 44

def row_struct
  @row_struct ||= Struct.new(*@columns.map { |c| c.select_alias.to_sym })
end