File: errors_serializer.rb

package info (click to toggle)
ruby-active-model-serializers 0.10.12-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,752 kB
  • sloc: ruby: 13,138; sh: 53; makefile: 6
file content (34 lines) | stat: -rw-r--r-- 749 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# frozen_string_literal: true

require 'active_model/serializer/error_serializer'

module ActiveModel
  class Serializer
    class ErrorsSerializer
      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 success?
        false
      end

      def json_key
        nil
      end

      protected

      attr_reader :serializers
    end
  end
end