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_json(_ = nil) ⇒ Object

accept arguments to work with rails rendering



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

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