Module: ROM::Processor::Transformer::Functions

Extended by:
Dry::Transformer::Registry
Defined in:
lib/rom/processor/transformer.rb

Constant Summary collapse

INVALID_INJECT_UNION_VALUE =
"%s attribute: block is required for :from with union value."

Class Method Summary collapse

Class Method Details

.filter_empty(arr) ⇒ Object


35
36
37
# File 'lib/rom/processor/transformer.rb', line 35

def self.filter_empty(arr)
  arr.reject { |row| row.values.all?(&:nil?) }
end

.get(arr, idx) ⇒ Object


31
32
33
# File 'lib/rom/processor/transformer.rb', line 31

def self.get(arr, idx)
  arr[idx]
end

.inject_union_value(tuple, name, keys, coercer) ⇒ Object


39
40
41
42
43
44
45
46
# File 'lib/rom/processor/transformer.rb', line 39

def self.inject_union_value(tuple, name, keys, coercer)
  raise ROM::MapperMisconfiguredError, INVALID_INJECT_UNION_VALUE % [name] unless coercer

  values = tuple.values_at(*keys)
  result = coercer.call(*values)

  tuple.merge(name => result)
end