Exception: APPI::Exception
- Inherits:
-
Exception
- Object
- Exception
- APPI::Exception
- Defined in:
- lib/appi/exception.rb
Instance Attribute Summary collapse
-
#code ⇒ Object
Returns the value of attribute code.
-
#detail ⇒ Object
Returns the value of attribute detail.
-
#details ⇒ Object
Returns the value of attribute details.
-
#status ⇒ Object
Returns the value of attribute status.
-
#title ⇒ Object
Returns the value of attribute title.
-
#validations ⇒ Object
Returns the value of attribute validations.
Instance Method Summary collapse
- #as_json ⇒ Object
- #base_error ⇒ Object
-
#initialize(code, details = {}, validations = {}) ⇒ Exception
constructor
A new instance of Exception.
- #validation_array ⇒ Object
Constructor Details
#initialize(code, details = {}, validations = {}) ⇒ Exception
Returns a new instance of Exception.
11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/appi/exception.rb', line 11 def initialize(code, details={}, validations={}) @details = details @code = code @validations = validations @status = I18n.t "appi_exceptions.#{code}.status" @title = I18n.t "appi_exceptions.#{code}.title", details @detail = I18n.t "appi_exceptions.#{code}.detail", details = @detail end |
Instance Attribute Details
#code ⇒ Object
Returns the value of attribute code.
4 5 6 |
# File 'lib/appi/exception.rb', line 4 def code @code end |
#detail ⇒ Object
Returns the value of attribute detail.
9 10 11 |
# File 'lib/appi/exception.rb', line 9 def detail @detail end |
#details ⇒ Object
Returns the value of attribute details.
3 4 5 |
# File 'lib/appi/exception.rb', line 3 def details @details end |
#status ⇒ Object
Returns the value of attribute status.
7 8 9 |
# File 'lib/appi/exception.rb', line 7 def status @status end |
#title ⇒ Object
Returns the value of attribute title.
8 9 10 |
# File 'lib/appi/exception.rb', line 8 def title @title end |
#validations ⇒ Object
Returns the value of attribute validations.
5 6 7 |
# File 'lib/appi/exception.rb', line 5 def validations @validations end |
Instance Method Details
#as_json ⇒ Object
45 46 47 48 49 |
# File 'lib/appi/exception.rb', line 45 def as_json { errors: validation_array.prepend(base_error) } end |
#base_error ⇒ Object
36 37 38 39 40 41 42 43 |
# File 'lib/appi/exception.rb', line 36 def base_error { title: title, detail: detail, code: code, status: status } end |
#validation_array ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/appi/exception.rb', line 23 def validation_array array = [] @validations.to_hash.each_key do |key| array << { title: @validations[key].uniq.join(', '), source: { pointer: "data/attributes/#{key}" } } end array end |