Class: Serializers::Base
- Inherits:
-
Object
- Object
- Serializers::Base
- Defined in:
- lib/template/lib/serializers/base.rb
Constant Summary collapse
- @@structures =
{}
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(type) ⇒ Base
constructor
A new instance of Base.
- #serialize(object) ⇒ Object
Constructor Details
#initialize(type) ⇒ Base
Returns a new instance of Base.
9 10 11 |
# File 'lib/template/lib/serializers/base.rb', line 9 def initialize(type) @type = type end |
Class Method Details
.structure(type, &blk) ⇒ Object
5 6 7 |
# File 'lib/template/lib/serializers/base.rb', line 5 def self.structure(type, &blk) @@structures["#{self.name}::#{type}"] = blk end |
Instance Method Details
#serialize(object) ⇒ Object
13 14 15 |
# File 'lib/template/lib/serializers/base.rb', line 13 def serialize(object) object.respond_to?(:map) ? object.map{|item| serializer.call(item)} : serializer.call(object) end |