mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-23 06:16:50 +00:00
- Separate collection errors from resource errors in adapter - Refactor to ErrorsSerializer; first-class json error methods - DOCS - Rails 4.0 requires assert exact exception class, boo
24 lines
604 B
Ruby
24 lines
604 B
Ruby
require 'active_model/serializer/error_serializer'
|
|
class ActiveModel::Serializer::ErrorsSerializer < ActiveModel::Serializer
|
|
include Enumerable
|
|
delegate :each, to: :@serializers
|
|
attr_reader :object, :root
|
|
|
|
def initialize(resources, options = {})
|
|
@root = options[:root]
|
|
@object = resources
|
|
@serializers = resources.map do |resource|
|
|
serializer_class = options.fetch(:serializer) { ActiveModel::Serializer::ErrorSerializer }
|
|
serializer_class.new(resource, options.except(:serializer))
|
|
end
|
|
end
|
|
|
|
def json_key
|
|
nil
|
|
end
|
|
|
|
protected
|
|
|
|
attr_reader :serializers
|
|
end
|