Class: ROM::Processor::Transformer

Inherits:
ROM::Processor show all
Includes:
Composer
Defined in:
lib/rom/processor/transformer.rb

Overview

Data mapping transformer builder using dry-transformer

This builds a transformer object that is used to map a whole relation

Defined Under Namespace

Modules: Functions

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(mapper, header) ⇒ Transformer

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Transformer.


86
87
88
89
90
91
92
# File 'lib/rom/processor/transformer.rb', line 86

def initialize(mapper, header)
  @mapper = mapper
  @header = header
  @model = header.model
  @mapping = header.mapping
  initialize_row_proc
end

Instance Attribute Details

#headerHeader (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns header from a mapper.

Returns:

  • (Header)

    header from a mapper


57
58
59
# File 'lib/rom/processor/transformer.rb', line 57

def header
  @header
end

#mapperMapper (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns mapper that this processor belongs to.

Returns:

  • (Mapper)

    mapper that this processor belongs to


52
53
54
# File 'lib/rom/processor/transformer.rb', line 52

def mapper
  @mapper
end

#mappingHash (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns header's attribute mapping.

Returns:

  • (Hash)

    header's attribute mapping


67
68
69
# File 'lib/rom/processor/transformer.rb', line 67

def mapping
  @mapping
end

#modelClass (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns model class from a mapper.

Returns:

  • (Class)

    model class from a mapper


62
63
64
# File 'lib/rom/processor/transformer.rb', line 62

def model
  @model
end

#row_procProc (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns row-processing proc.

Returns:

  • (Proc)

    row-processing proc


72
73
74
# File 'lib/rom/processor/transformer.rb', line 72

def row_proc
  @row_proc
end

Class Method Details

.build(mapper, header) ⇒ Dry::Transformer::Pipe

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Build a transformer object from the header

Parameters:

Returns:

  • (Dry::Transformer::Pipe)

81
82
83
# File 'lib/rom/processor/transformer.rb', line 81

def self.build(mapper, header)
  new(mapper, header).call
end

Instance Method Details

#callDry::Transformer::Pipe

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Coerce mapper header to a transformer object

Returns:

  • (Dry::Transformer::Pipe)

99
100
101
102
103
104
105
106
107
# File 'lib/rom/processor/transformer.rb', line 99

def call
  compose(t(:identity)) do |ops|
    combined = header.combined
    ops << t(:combine, combined.map(&method(:combined_args))) if combined.any?
    ops << header.preprocessed.map { |attr| visit(attr, true) }
    ops << t(:map_array, row_proc) if row_proc
    ops << header.postprocessed.map { |attr| visit(attr, true) }
  end
end

#compose(default = nil) {|factory| ... } ⇒ Object Originally defined in module Composer

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Yields:

  • (factory)