Class: ROM::Processor::Transproc
- Inherits:
-
ROM::Processor
- Object
- ROM::Processor
- ROM::Processor::Transproc
- Includes:
- Transproc::Composer
- Defined in:
- lib/rom/processor/transproc.rb
Overview
Data mapping transformer builder using Transproc
This builds a transproc function 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) ⇒ Transproc::Function
private
Build a transproc function from the header.
Instance Method Summary collapse
-
#initialize(mapper, header) ⇒ Transproc
constructor
private
A new instance of Transproc.
-
#to_transproc ⇒ Transproc::Function
private
Coerce mapper header to a transproc data mapping function.
Methods inherited from ROM::Processor
Constructor Details
#initialize(mapper, header) ⇒ Transproc
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 Transproc.
79 80 81 82 83 84 85 |
# File 'lib/rom/processor/transproc.rb', line 79 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.
50 51 52 |
# File 'lib/rom/processor/transproc.rb', line 50 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.
45 46 47 |
# File 'lib/rom/processor/transproc.rb', line 45 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.
60 61 62 |
# File 'lib/rom/processor/transproc.rb', line 60 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.
55 56 57 |
# File 'lib/rom/processor/transproc.rb', line 55 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.
65 66 67 |
# File 'lib/rom/processor/transproc.rb', line 65 def row_proc @row_proc end |
Class Method Details
.build(mapper, header) ⇒ Transproc::Function
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 transproc function from the header
74 75 76 |
# File 'lib/rom/processor/transproc.rb', line 74 def self.build(mapper, header) new(mapper, header).to_transproc end |
Instance Method Details
#to_transproc ⇒ Transproc::Function
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 transproc data mapping function
92 93 94 95 96 97 98 99 100 |
# File 'lib/rom/processor/transproc.rb', line 92 def to_transproc 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 |