Class: PlainSerializer::Base
- Inherits:
-
Object
- Object
- PlainSerializer::Base
- Includes:
- Configurable, Modifiable, Serializable
- Defined in:
- lib/plain_serializer/base.rb
Overview
The base class
Instance Method Summary collapse
-
#initialize(*args) ⇒ Base
constructor
A new instance of Base.
- #serialize(entity) ⇒ Object
- #serialize_collection(entities) ⇒ Object
Methods included from Configurable
Methods included from Serializable
included, #serializer, #serializers, #setup_serializer
Constructor Details
Instance Method Details
#serialize(entity) ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/plain_serializer/base.rb', line 17 def serialize(entity) return if entity.nil? @attributes.each_with_object({}) do |attribute, result| result[attribute] = send(attribute, entity) end end |
#serialize_collection(entities) ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/plain_serializer/base.rb', line 25 def serialize_collection(entities) return if entities.nil? entities.each_with_object([]) do |entity, result| result << serialize(entity) end end |