class Cereals::ArraySerializer
Public Class Methods
new(objects, root)
click to toggle source
objects must respond to :serializer root is a string, the name of the root JSON key
# File lib/cereals/array_serializer.rb, line 7 def initialize(objects, root) @objects = objects @root = root end
Public Instance Methods
to_json(_ = nil)
click to toggle source
accept arguments to work with rails rendering
# File lib/cereals/array_serializer.rb, line 13 def to_json(_ = nil) { @root => wrap_objects.as_json(root: false) }.to_json end
Private Instance Methods
wrap_objects()
click to toggle source
# File lib/cereals/array_serializer.rb, line 19 def wrap_objects @objects.map(&:serializer) end