class Seri::GroupSerializer

Public Class Methods

new(objects, serializer: nil, scope: {}) click to toggle source
# File lib/serializer/group_serializer.rb, line 3
def initialize(objects, serializer: nil, scope: {})
  raise ArgumentError, 'serializer needs to be specified' if serializer.nil?

  @objects = objects
  @serializer = serializer
  @scope = scope
end

Public Instance Methods

to_h() click to toggle source
# File lib/serializer/group_serializer.rb, line 15
def to_h
  @objects
    .map { |object| @serializer.new(object, scope: @scope) }
    .map(&:to_h)
end
to_json(*) click to toggle source
# File lib/serializer/group_serializer.rb, line 11
def to_json(*)
  Oj.dump(to_h, mode: :json)
end