Class: FlexTrans::Mapper
- Inherits:
-
Object
- Object
- FlexTrans::Mapper
- Defined in:
- lib/flex_trans/mapper.rb
Class Method Summary collapse
Instance Method Summary collapse
- #current_mapping_attributes ⇒ Object
- #current_mapping_type ⇒ Object
-
#initialize(mapping_attributes: [], mapping_type: nil) ⇒ Mapper
constructor
A new instance of Mapper.
- #map(relation, limit: nil) ⇒ Object
- #mapping_attributes(*mapping_attributes) ⇒ Object
- #mapping_type(mapping_type) ⇒ Object
Constructor Details
#initialize(mapping_attributes: [], mapping_type: nil) ⇒ Mapper
Returns a new instance of Mapper.
15 16 17 18 |
# File 'lib/flex_trans/mapper.rb', line 15 def initialize(mapping_attributes: [], mapping_type: nil) @mapping_attributes = mapping_attributes @mapping_type = mapping_type end |
Class Method Details
.mapping_attributes(*mapping_attributes) ⇒ Object
6 7 8 |
# File 'lib/flex_trans/mapper.rb', line 6 def mapping_attributes(*mapping_attributes) new(mapping_attributes: mapping_attributes) end |
.mapping_type(mapping_type) ⇒ Object
10 11 12 |
# File 'lib/flex_trans/mapper.rb', line 10 def mapping_type(mapping_type) new(mapping_type: mapping_type) end |
Instance Method Details
#current_mapping_attributes ⇒ Object
42 43 44 |
# File 'lib/flex_trans/mapper.rb', line 42 def current_mapping_attributes @mapping_attributes end |
#current_mapping_type ⇒ Object
38 39 40 |
# File 'lib/flex_trans/mapper.rb', line 38 def current_mapping_type @mapping_type || FlexTrans::Struct.new(*current_mapping_attributes) end |
#map(relation, limit: nil) ⇒ Object
29 30 31 32 33 34 35 36 |
# File 'lib/flex_trans/mapper.rb', line 29 def map(relation, limit: nil) # Just fake it [current_mapping_type.new(id: 1, name: 'Akira Suenami')] # relation.limit(limit).pluck(attributes).map do |record| # mapping_type.new(record) # end end |
#mapping_attributes(*mapping_attributes) ⇒ Object
20 21 22 23 |
# File 'lib/flex_trans/mapper.rb', line 20 def mapping_attributes(*mapping_attributes) new_attribues = (@mapping_attributes + mapping_attributes).uniq self.class.new(mapping_attributes: new_attribues, mapping_type: @mapping_type) end |
#mapping_type(mapping_type) ⇒ Object
25 26 27 |
# File 'lib/flex_trans/mapper.rb', line 25 def mapping_type(mapping_type) self.class.new(mapping_attributes: @mapping_attributes, mapping_type: mapping_type) end |