Class: Ivy::Serializers::Attribute

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

Instance Method Summary collapse

Constructor Details

#initialize(name, &getter) ⇒ Attribute

Returns a new instance of Attribute.



4
5
6
7
# File 'lib/ivy/serializers/attribute.rb', line 4

def initialize(name, &getter)
  @name = name
  @getter = getter || method(:default_getter)
end

Instance Method Details

#generate(generator, resource) ⇒ Object



9
10
11
# File 'lib/ivy/serializers/attribute.rb', line 9

def generate(generator, resource)
  generator.attribute(@name, get(resource))
end