Class: Spage::Serializers::Component

Inherits:
Object
  • Object
show all
Defined in:
lib/spage/serializers/component.rb

Overview

Serializer for the Component resource

Instance Method Summary collapse

Constructor Details

#initialize(component, update: false) ⇒ Component

Returns a new instance of Component.



8
9
10
11
# File 'lib/spage/serializers/component.rb', line 8

def initialize(component, update: false)
  @component = component
  @ivars = ivars(update)
end

Instance Method Details

#as_jsonObject



17
18
19
# File 'lib/spage/serializers/component.rb', line 17

def as_json
  to_hash
end

#to_hashObject



21
22
23
24
25
26
27
28
29
# File 'lib/spage/serializers/component.rb', line 21

def to_hash
  {
    'component' => Hash[
      @ivars.map do |name|
        [name[1..-1], @component.instance_variable_get(name)]
      end
    ]
  }
end

#to_json(obj = nil) ⇒ Object



13
14
15
# File 'lib/spage/serializers/component.rb', line 13

def to_json(obj = nil)
  as_json.to_json(obj)
end