Class: Spage::Serializers::Component
- Inherits:
-
Object
- Object
- Spage::Serializers::Component
- Defined in:
- lib/spage/serializers/component.rb
Overview
Serializer for the Component resource
Instance Method Summary collapse
- #as_json ⇒ Object
-
#initialize(component, update: false) ⇒ Component
constructor
A new instance of Component.
- #to_hash ⇒ Object
- #to_json(obj = nil) ⇒ Object
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_json ⇒ Object
17 18 19 |
# File 'lib/spage/serializers/component.rb', line 17 def as_json to_hash end |
#to_hash ⇒ Object
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 |