Class: USerializer::CompositeObject

Inherits:
Object
  • Object
show all
Defined in:
lib/userializer/composite_serializer.rb

Instance Method Summary collapse

Constructor Details

#initialize(obj, opts = {}) ⇒ CompositeObject

Returns a new instance of CompositeObject.



5
6
7
8
9
10
11
12
13
14
15
# File 'lib/userializer/composite_serializer.rb', line 5

def initialize(obj, opts = {})
  @obj = obj
  @opts = opts
  @root_key = opts[:root].to_sym
  serializer = opts[:serializer]
  @serializer = if serializer.is_a?(Proc)
                  serializer
                elsif serializer
                  proc { serializer }
                end
end

Instance Method Details

#merge_root(res, opts) ⇒ Object



17
18
19
# File 'lib/userializer/composite_serializer.rb', line 17

def merge_root(res, opts)
  serializer(@obj, opts).merge_root(res, @root_key, true, opts)
end