Class: JSONAPIHelpers::Serializers::Error

Inherits:
Object
  • Object
show all
Defined in:
lib/jsonapi_helpers/serializers/error.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(detail:, status: 422, code: nil, pointer: nil, attribute: nil, key_transform: JSONAPIHelpers.config.key_transform) ⇒ Error

Returns a new instance of Error.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# 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

Instance Attribute Details

#codeObject (readonly)

Returns the value of attribute code.



6
7
8
# File 'lib/jsonapi_helpers/serializers/error.rb', line 6

def code
  @code
end

#detailObject (readonly)

Returns the value of attribute detail.



6
7
8
# File 'lib/jsonapi_helpers/serializers/error.rb', line 6

def detail
  @detail
end

#statusObject (readonly)

Returns the value of attribute status.



6
7
8
# File 'lib/jsonapi_helpers/serializers/error.rb', line 6

def status
  @status
end

Instance Method Details

#to_hObject



26
27
28
29
30
# 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