Class: RubySerializer::Base

Inherits:
Object
  • Object
show all
Extended by:
Dsl
Defined in:
lib/ruby_serializer/base.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Dsl

expose, fields, serializes

Constructor Details

#initialize(resource) ⇒ Base

only populated during #serialize and (temporarily) stores the #serialize options to make them available to any potential :value, :only and :unless lambdas in the derived serializer



9
10
11
# File 'lib/ruby_serializer/base.rb', line 9

def initialize(resource)
  @resource = resource
end

Instance Attribute Details

#includeObject (readonly)

Returns the value of attribute include.



6
7
8
# File 'lib/ruby_serializer/base.rb', line 6

def include
  @include
end

#optionsObject (readonly)

Returns the value of attribute options.



6
7
8
# File 'lib/ruby_serializer/base.rb', line 6

def options
  @options
end

Instance Method Details

#as_json(options = {}) ⇒ Object



13
14
15
16
17
# File 'lib/ruby_serializer/base.rb', line 13

def as_json(options = {})
  json = serialize(options)
  json = { options[:root] => json } if options[:root]
  json
end