Module: Simple::SQL::Helpers::RowConverter

Defined in:
lib/simple/sql/helpers/row_converter.rb

Defined Under Namespace

Classes: StructConverter

Class Method Summary collapse

Class Method Details

.convert(records, into:) ⇒ Object

returns an array of converted records



3
4
5
6
7
8
9
10
11
12
13
# File 'lib/simple/sql/helpers/row_converter.rb', line 3

def self.convert(records, into:)
  hsh = records.first
  return records unless hsh

  if into == :struct
    converter = StructConverter.for(attributes: hsh.keys)
    records.map { |record| converter.convert(record) }
  else
    records.map { |record| into.new(record) }
  end
end