Class: JSONAPI::Error
- Inherits:
-
Object
- Object
- JSONAPI::Error
- Defined in:
- lib/jsonapi/error.rb
Instance Attribute Summary collapse
-
#code ⇒ Object
Returns the value of attribute code.
-
#detail ⇒ Object
Returns the value of attribute detail.
-
#href ⇒ Object
Returns the value of attribute href.
-
#id ⇒ Object
Returns the value of attribute id.
-
#links ⇒ Object
Returns the value of attribute links.
-
#meta ⇒ Object
Returns the value of attribute meta.
-
#source ⇒ Object
Returns the value of attribute source.
-
#status ⇒ Object
Returns the value of attribute status.
-
#title ⇒ Object
Returns the value of attribute title.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Error
constructor
A new instance of Error.
- #to_hash ⇒ Object
- #update_with_overrides(error_object_overrides) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Error
Returns a new instance of Error.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/jsonapi/error.rb', line 7 def initialize( = {}) @title = [:title] @detail = [:detail] @id = [:id] @href = [:href] @code = if JSONAPI.configuration.use_text_errors TEXT_ERRORS[[:code]] else [:code] end @source = [:source] @links = [:links] @status = Rack::Utils.status_code([:status]).to_s @meta = [:meta] end |
Instance Attribute Details
#code ⇒ Object
Returns the value of attribute code.
5 6 7 |
# File 'lib/jsonapi/error.rb', line 5 def code @code end |
#detail ⇒ Object
Returns the value of attribute detail.
5 6 7 |
# File 'lib/jsonapi/error.rb', line 5 def detail @detail end |
#href ⇒ Object
Returns the value of attribute href.
5 6 7 |
# File 'lib/jsonapi/error.rb', line 5 def href @href end |
#id ⇒ Object
Returns the value of attribute id.
5 6 7 |
# File 'lib/jsonapi/error.rb', line 5 def id @id end |
#links ⇒ Object
Returns the value of attribute links.
5 6 7 |
# File 'lib/jsonapi/error.rb', line 5 def links @links end |
#meta ⇒ Object
Returns the value of attribute meta.
5 6 7 |
# File 'lib/jsonapi/error.rb', line 5 def @meta end |
#source ⇒ Object
Returns the value of attribute source.
5 6 7 |
# File 'lib/jsonapi/error.rb', line 5 def source @source end |
#status ⇒ Object
Returns the value of attribute status.
5 6 7 |
# File 'lib/jsonapi/error.rb', line 5 def status @status end |
#title ⇒ Object
Returns the value of attribute title.
5 6 7 |
# File 'lib/jsonapi/error.rb', line 5 def title @title end |
Instance Method Details
#to_hash ⇒ Object
24 25 26 27 28 |
# File 'lib/jsonapi/error.rb', line 24 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
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/jsonapi/error.rb', line 30 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 |