class Serializers::Base
Public Class Methods
new(type)
click to toggle source
# File lib/template/lib/serializers/base.rb, line 11 def initialize(type) @type = type end
structure(type, &blk)
click to toggle source
# File lib/template/lib/serializers/base.rb, line 7 def self.structure(type, &blk) @@structures["#{name}::#{type}"] = blk end
Public Instance Methods
serialize(object)
click to toggle source
# File lib/template/lib/serializers/base.rb, line 15 def serialize(object) object.respond_to?(:map) ? object.map { |item| serializer.call(item) } : serializer.call(object) end
Private Instance Methods
serializer()
click to toggle source
# File lib/template/lib/serializers/base.rb, line 21 def serializer @@structures["#{self.class.name}::#{@type}"] end