Class: Spage::Serializers::Page
- Inherits:
-
Object
- Object
- Spage::Serializers::Page
- Defined in:
- lib/spage/serializers/page.rb
Overview
Serializer for the Page resource
Instance Method Summary collapse
- #as_json ⇒ Object
-
#initialize(page, update: false) ⇒ Page
constructor
A new instance of Page.
- #to_hash ⇒ Object
- #to_json(obj = nil) ⇒ Object
Constructor Details
#initialize(page, update: false) ⇒ Page
Returns a new instance of Page.
8 9 10 11 |
# File 'lib/spage/serializers/page.rb', line 8 def initialize(page, update: false) @page = page @ivars = ivars(update) end |
Instance Method Details
#as_json ⇒ Object
17 18 19 |
# File 'lib/spage/serializers/page.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/page.rb', line 21 def to_hash { 'page' => Hash[ @ivars.map do |name| [name[1..-1], @page.instance_variable_get(name)] end ] } end |
#to_json(obj = nil) ⇒ Object
13 14 15 |
# File 'lib/spage/serializers/page.rb', line 13 def to_json(obj = nil) as_json.to_json(obj) end |