mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-23 06:16:50 +00:00
27 lines
598 B
Ruby
27 lines
598 B
Ruby
module ActiveModel
|
|
class Serializer
|
|
class ArraySerializer
|
|
include Enumerable
|
|
delegate :each, to: :@objects
|
|
|
|
def initialize(objects, options = {})
|
|
@objects = objects.map do |object|
|
|
serializer_class = options.fetch(
|
|
:serializer,
|
|
ActiveModel::Serializer.serializer_for(object)
|
|
)
|
|
serializer_class.new(object)
|
|
end
|
|
end
|
|
|
|
def json_key
|
|
@objects.first.json_key if @objects.first
|
|
end
|
|
|
|
def root=(root)
|
|
@objects.first.root = root if @objects.first
|
|
end
|
|
end
|
|
end
|
|
end
|