Class: LunaPark::Mappers::Codirectional::Copyists::Nested

Inherits:
Object
  • Object
show all
Defined in:
lib/luna_park/mappers/codirectional/copyists/nested.rb

Overview

Copyist for copiyng value between two schemas with DIFFERENT or NESTED paths

(Works with only one described attribute)

Instance Method Summary collapse

Constructor Details

#initialize(attrs_path:, row_path:, mapper:, map_array:) ⇒ Nested

Returns a new instance of Nested.

Raises:

  • (ArgumentError)


10
11
12
13
14
15
16
17
18
19
20
# File 'lib/luna_park/mappers/codirectional/copyists/nested.rb', line 10

def initialize(attrs_path:, row_path:, mapper:, map_array:)
  @attrs_path = attrs_path
  @row_path   = row_path

  @mapper_config = mapper
  @map_array     = map_array

  raise ArgumentError, 'attr path can not be nil'  if attrs_path.nil?
  raise ArgumentError, 'store path can not be nil' if row_path.nil?
  raise ArgumentError, 'array option MUST be nil when no Mapper given' if map_array && mapper.nil?
end

Instance Method Details

#from_row(row:, attrs:) ⇒ Object



22
23
24
# File 'lib/luna_park/mappers/codirectional/copyists/nested.rb', line 22

def from_row(row:, attrs:)
  copy_nested(from: row, to: attrs, from_path: @row_path, to_path: @attrs_path, direction: :from_row)
end

#to_row(row:, attrs:) ⇒ Object



26
27
28
# File 'lib/luna_park/mappers/codirectional/copyists/nested.rb', line 26

def to_row(row:, attrs:)
  copy_nested(from: attrs, to: row, from_path: @attrs_path, to_path: @row_path, direction: :to_row)
end