Sha256: f58e0a3bc19b3d3657426baf215806d36a7f69ad4f0ee40ef78a409edee47ecd

Contents?: true

Size: 583 Bytes

Versions: 25

Compression:

Stored size: 583 Bytes

Contents

require 'fast_jsonapi'

module JSONAPI
  # A simple error serializer
  class ErrorSerializer
    include FastJsonapi::ObjectSerializer

    set_id :object_id
    set_type :error

    # Object/Hash attribute helpers.
    [:status, :source, :title, :detail].each do |attr_name|
      attribute attr_name do |object|
        object.try(attr_name) || object.try(:fetch, attr_name, nil)
      end
    end

    # Remap the root key to `errors`
    #
    # @return [Hash]
    def serializable_hash
      { errors: (super[:data] || []).map { |error| error[:attributes] } }
    end
  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
jsonapi.rb-1.1.3 lib/jsonapi/error_serializer.rb
jsonapi.rb-1.1.2 lib/jsonapi/error_serializer.rb
jsonapi.rb-1.1.1 lib/jsonapi/error_serializer.rb
jsonapi.rb-1.1.0 lib/jsonapi/error_serializer.rb
jsonapi.rb-1.0.0 lib/jsonapi/error_serializer.rb