Class: Serializers::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/template/lib/serializers/base.rb

Constant Summary collapse

@@structures =
{}

Class Method Summary collapse

Instance Method Summary collapse

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