Class: Prototok::Serializers::Attribute

Inherits:
Object
  • Object
show all
Defined in:
lib/prototok/attribute.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Attribute

Returns a new instance of Attribute.



7
8
9
10
# File 'lib/prototok/attribute.rb', line 7

def initialize(options)
  @options = options || {}
  @serializer = Serializers.find(@options[:serializer])
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



4
5
6
# File 'lib/prototok/attribute.rb', line 4

def options
  @options
end

#serializerObject (readonly)

Returns the value of attribute serializer.



5
6
7
# File 'lib/prototok/attribute.rb', line 5

def serializer
  @serializer
end

Instance Method Details

#serialize(value) ⇒ Object



12
13
14
15
16
17
18
# File 'lib/prototok/attribute.rb', line 12

def serialize(value)
  if @serializer
    @serializer.new(value).encode
  else
    value
  end
end