class JSONAPIHelpers::Serializers::Error
Attributes
code[R]
detail[R]
status[R]
Public Class Methods
new( detail:, status: 422, code: nil, pointer: nil, attribute: nil, key_transform: JSONAPIHelpers.config.key_transform )
click to toggle source
# File lib/jsonapi_helpers/serializers/error.rb, line 8 def initialize( detail:, status: 422, code: nil, pointer: nil, attribute: nil, key_transform: JSONAPIHelpers.config.key_transform ) @status = status @detail = detail @pointer = pointer( pointer: pointer, attribute: attribute, key_transform: key_transform ) @code = code end
Public Instance Methods
to_h()
click to toggle source
# File lib/jsonapi_helpers/serializers/error.rb, line 26 def to_h response = { status: @status, detail: @detail } response[:code] = @code unless @code.nil? response.merge!(@pointer) end
Private Instance Methods
attribute_pointer(attribute, key_transform:)
click to toggle source
# File lib/jsonapi_helpers/serializers/error.rb, line 49 def attribute_pointer(attribute, key_transform:) attribute_name = KeyTransform.call(attribute.to_s, key_transform: key_transform) "/data/attributes/#{attribute_name}" end
pointer(pointer:, attribute:, key_transform:)
click to toggle source
# File lib/jsonapi_helpers/serializers/error.rb, line 34 def pointer(pointer:, attribute:, key_transform:) return {} if pointer.nil? && attribute.nil? full_pointer = if pointer pointer else attribute_pointer(attribute, key_transform: key_transform) end { source: { pointer: full_pointer } } end