Class: ROM::Processor::Transformer
- Inherits:
-
ROM::Processor
- Object
- ROM::Processor
- ROM::Processor::Transformer
- 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
-
#header ⇒ Header
readonly
private
Header from a mapper.
-
#mapper ⇒ Mapper
readonly
private
Mapper that this processor belongs to.
-
#mapping ⇒ Hash
readonly
private
Header's attribute mapping.
-
#model ⇒ Class
readonly
private
Model class from a mapper.
-
#row_proc ⇒ Proc
readonly
private
Row-processing proc.
Class Method Summary collapse
-
.build(mapper, header) ⇒ Dry::Transformer::Pipe
private
Build a transformer object from the header.
Instance Method Summary collapse
-
#call ⇒ Dry::Transformer::Pipe
private
Coerce mapper header to a transformer object.
- #compose(default = nil) {|factory| ... } ⇒ Object included from Composer private
-
#initialize(mapper, header) ⇒ Transformer
constructor
private
A new instance of Transformer.
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.
84 85 86 87 88 89 90 |
# File 'lib/rom/processor/transformer.rb', line 84 def initialize(mapper, header) @mapper = mapper @header = header @model = header.model @mapping = header.mapping initialize_row_proc end |
Instance Attribute Details
#header ⇒ Header (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.
55 56 57 |
# File 'lib/rom/processor/transformer.rb', line 55 def header @header end |
#mapper ⇒ Mapper (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.
50 51 52 |
# File 'lib/rom/processor/transformer.rb', line 50 def mapper @mapper end |
#mapping ⇒ Hash (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.
65 66 67 |
# File 'lib/rom/processor/transformer.rb', line 65 def mapping @mapping end |
#model ⇒ Class (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.
60 61 62 |
# File 'lib/rom/processor/transformer.rb', line 60 def model @model end |
#row_proc ⇒ Proc (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.
70 71 72 |
# File 'lib/rom/processor/transformer.rb', line 70 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
79 80 81 |
# File 'lib/rom/processor/transformer.rb', line 79 def self.build(mapper, header) new(mapper, header).call end |
Instance Method Details
#call ⇒ 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.
Coerce mapper header to a transformer object
97 98 99 100 101 102 103 104 105 |
# File 'lib/rom/processor/transformer.rb', line 97 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.