Class: JSONAPI::Error

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Error

Returns a new instance of Error.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/jsonapi/error.rb', line 5

def initialize(options = {})
  @title          = options[:title]
  @detail         = options[:detail]
  @id             = options[:id]
  @href           = options[:href]
  @code           = if JSONAPI.configuration.use_text_errors
                      TEXT_ERRORS[options[:code]]
                    else
                      options[:code]
                    end
  @source         = options[:source]
  @links          = options[:links]

  @status         = Rack::Utils::SYMBOL_TO_STATUS_CODE[options[:status]].to_s
  @meta           = options[:meta]
end

Instance Attribute Details

#codeObject

Returns the value of attribute code.



3
4
5
# File 'lib/jsonapi/error.rb', line 3

def code
  @code
end

#detailObject

Returns the value of attribute detail.



3
4
5
# File 'lib/jsonapi/error.rb', line 3

def detail
  @detail
end

#hrefObject

Returns the value of attribute href.



3
4
5
# File 'lib/jsonapi/error.rb', line 3

def href
  @href
end

#idObject

Returns the value of attribute id.



3
4
5
# File 'lib/jsonapi/error.rb', line 3

def id
  @id
end

Returns the value of attribute links.



3
4
5
# File 'lib/jsonapi/error.rb', line 3

def links
  @links
end

#metaObject

Returns the value of attribute meta.



3
4
5
# File 'lib/jsonapi/error.rb', line 3

def meta
  @meta
end

#sourceObject

Returns the value of attribute source.



3
4
5
# File 'lib/jsonapi/error.rb', line 3

def source
  @source
end

#statusObject

Returns the value of attribute status.



3
4
5
# File 'lib/jsonapi/error.rb', line 3

def status
  @status
end

#titleObject

Returns the value of attribute title.



3
4
5
# File 'lib/jsonapi/error.rb', line 3

def title
  @title
end

Instance Method Details

#to_hashObject



22
23
24
25
26
# File 'lib/jsonapi/error.rb', line 22

def to_hash
  hash = {}
  instance_variables.each {|var| hash[var.to_s.delete('@')] = instance_variable_get(var) unless instance_variable_get(var).nil? }
  hash
end

#update_with_overrides(error_object_overrides) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/jsonapi/error.rb', line 28

def update_with_overrides(error_object_overrides)
  @title          = error_object_overrides[:title] || @title
  @detail         = error_object_overrides[:detail] || @detail
  @id             = error_object_overrides[:id] || @id
  @href           = error_object_overrides[:href] || href

  if error_object_overrides[:code]
    # :nocov:
    @code           = if JSONAPI.configuration.use_text_errors
                        TEXT_ERRORS[error_object_overrides[:code]]
                      else
                        error_object_overrides[:code]
                      end
    # :nocov:
  end

  @source         = error_object_overrides[:source] || @source
  @links          = error_object_overrides[:links] || @links

  if error_object_overrides[:status]
    # :nocov:
    @status         = Rack::Utils::SYMBOL_TO_STATUS_CODE[error_object_overrides[:status]].to_s
    # :nocov:
  end
  @meta           = error_object_overrides[:meta] || @meta
end