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

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

Defined Under Namespace

Classes: StructConverter, TypeConverter

Constant Summary collapse

SELF =
self

Class Method Summary collapse

Class Method Details

.convert(record, into:) ⇒ Object

:nodoc:



18
19
20
21
# File 'lib/simple/sql/helpers/row_converter.rb', line 18

def self.convert(record, into:) # :nodoc:
  ary = convert_row([record], into: into)
  ary.first
end

.convert_row(records, into:, associations: nil) ⇒ Object

returns an array of converted records



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

def self.convert_row(records, into:, associations: nil)
  hsh = records.first
  return records unless hsh

  converter = if into == :struct
                StructConverter.for(attributes: hsh.keys, associations: associations)
              else
                TypeConverter.for(type: into, associations: associations)
              end

  records.map { |record| converter.convert_row(record) }
end