Class: Cereals::ArraySerializer

Inherits:
Object
  • Object
show all
Defined in:
lib/cereals/array_serializer.rb

Instance Method Summary collapse

Constructor Details

#initialize(objects, root) ⇒ ArraySerializer

objects must respond to :serializer root is a string, the name of the root JSON key



7
8
9
10
# File 'lib/cereals/array_serializer.rb', line 7

def initialize(objects, root)
  @objects = objects
  @root = root
end

Instance Method Details

#to_jsonObject



12
13
14
# File 'lib/cereals/array_serializer.rb', line 12

def to_json
  { @root => wrap_objects.as_json(root: false) }.to_json
end