Class: LunaPark::Mappers::Simple
- Inherits:
-
Object
- Object
- LunaPark::Mappers::Simple
- Defined in:
- lib/luna_park/mappers/simple.rb
Overview
Abstract mapper for transform data from Entity attributes schema to Database row schema
Direct Known Subclasses
Class Method Summary collapse
- .from_row(row) ⇒ Object abstract
-
.from_rows(rows) ⇒ Object
Transforms array of rows to array of attribute hashes.
- .to_row(attrs) ⇒ Object abstract
-
.to_rows(attrs_array) ⇒ Object
Transforms array of attribute hashes to array of rows.
Class Method Details
.from_row(row) ⇒ Object
This method is abstract.
87 88 89 |
# File 'lib/luna_park/mappers/simple.rb', line 87 def from_row(row) row.to_h end |
.from_rows(rows) ⇒ Object
Transforms array of rows to array of attribute hashes
68 69 70 71 72 73 74 |
# File 'lib/luna_park/mappers/simple.rb', line 68 def from_rows(rows) return [] if rows.nil? raise Errors::NotArray.new(input: rows) if rows.is_a?(Hash) raise Errors::NotArray.new(input: rows) unless rows.respond_to?(:to_a) rows.to_a.map { |hash| from_row(hash) } end |
.to_row(attrs) ⇒ Object
This method is abstract.
92 93 94 |
# File 'lib/luna_park/mappers/simple.rb', line 92 def to_row(attrs) attrs.to_h end |
.to_rows(attrs_array) ⇒ Object
Transforms array of attribute hashes to array of rows
78 79 80 81 82 83 84 |
# File 'lib/luna_park/mappers/simple.rb', line 78 def to_rows(attrs_array) return [] if attrs_array.nil? raise Errors::NotArray.new(input: rows) if attrs_array.is_a?(Hash) raise Errors::NotArray.new(input: attrs_array) unless attrs_array.respond_to?(:to_a) attrs_array.to_a.map { |entity| to_row(entity) } end |