Exception: Controls::Error
- Inherits:
-
StandardError
- Object
- StandardError
- Controls::Error
- Defined in:
- lib/controls/objects/error.rb
Overview
A class under the Controls namespace to wrap API errors
- review
-
subclass Dish::Plate instead of StandardError?
-
Instance Attribute Summary collapse
-
#message ⇒ String
writeonly
The message related to the error.
-
#status ⇒ String
The status code for the error response.
Instance Method Summary collapse
-
#initialize(attributes = {}) ⇒ self
constructor
The Error with the given attributes.
-
#inspect ⇒ String
A string representing the error and all of it’s attributes.
-
#to_h ⇒ Hash
The attributes used to initialize this error.
-
#to_json ⇒ String
The JSON representation of the attributes.
-
#to_s ⇒ String
The error message if available otherwise calls #inspect.
Constructor Details
#initialize(attributes = {}) ⇒ self
Returns the Controls::Error with the given attributes.
17 18 19 20 21 22 |
# File 'lib/controls/objects/error.rb', line 17 def initialize(attributes = {}) @__attributes__ = attributes @__attributes__.each do |attribute, value| instance_variable_set(:"@#{attribute}", value) end end |
Instance Attribute Details
#message=(value) ⇒ String
Returns the message related to the error.
10 11 12 |
# File 'lib/controls/objects/error.rb', line 10 def @message end |
#status ⇒ String
Returns the status code for the error response.
10 |
# File 'lib/controls/objects/error.rb', line 10 attr_accessor :message, :status |
Instance Method Details
#inspect ⇒ String
Returns a string representing the error and all of it’s attributes.
26 27 28 29 30 31 32 |
# File 'lib/controls/objects/error.rb', line 26 def inspect vars = to_h.map do |attribute, value| "#{attribute}: #{value}" end "#<#{self.class}: #{vars.join(', ')}>" end |
#to_h ⇒ Hash
Returns the attributes used to initialize this error.
40 41 42 |
# File 'lib/controls/objects/error.rb', line 40 def to_h @__attributes__ end |
#to_json ⇒ String
Returns the JSON representation of the attributes.
35 36 37 |
# File 'lib/controls/objects/error.rb', line 35 def to_json @__attributes__.to_json end |
#to_s ⇒ String
Returns the error message if available otherwise calls #inspect.
45 46 47 |
# File 'lib/controls/objects/error.rb', line 45 def to_s @message or inspect end |