Class: Inthegra::BaseSerializer
- Inherits:
-
Object
- Object
- Inthegra::BaseSerializer
- Defined in:
- lib/inthegra/serializer/base.rb
Overview
Generic serialize class
Direct Known Subclasses
Instance Attribute Summary collapse
-
#input ⇒ Array:Hash
readonly
The input data.
-
#model ⇒ BaseModel
readonly
The model of collection.
-
#output ⇒ Array:BaseModel
readonly
The output data.
Class Method Summary collapse
-
.parse(input, model) ⇒ Object
Decorator method for the serializer.
Instance Method Summary collapse
-
#initialize(data, model) ⇒ BaseSerializer
constructor
Initialize the serializer passing a input data and a model.
-
#parse ⇒ Object
Implementation of the parser.
Constructor Details
#initialize(data, model) ⇒ BaseSerializer
Initialize the serializer passing a input data and a model
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/inthegra/serializer/base.rb', line 18 def initialize(data, model) data ||= [] unless data.is_a?(Array) raise InvalidSerializerInput, "The data is a #{data.class} and not a Array type" end @model = model @input = data end |
Instance Attribute Details
#input ⇒ Array:Hash (readonly)
Returns the input data.
6 7 8 |
# File 'lib/inthegra/serializer/base.rb', line 6 def input @input end |
#model ⇒ BaseModel (readonly)
Returns the model of collection.
12 13 14 |
# File 'lib/inthegra/serializer/base.rb', line 12 def model @model end |
#output ⇒ Array:BaseModel (readonly)
Returns the output data.
9 10 11 |
# File 'lib/inthegra/serializer/base.rb', line 9 def output @output end |
Class Method Details
.parse(input, model) ⇒ Object
Decorator method for the serializer
35 36 37 |
# File 'lib/inthegra/serializer/base.rb', line 35 def self.parse(input, model) @output = new(input, model).parse end |
Instance Method Details
#parse ⇒ Object
Implementation of the parser
40 41 42 |
# File 'lib/inthegra/serializer/base.rb', line 40 def parse raise NotImplementedError.new end |