class Controls::Error
A class under the Controls
namespace to wrap API errors
- review
-
subclass
Dish::Plate
instead of StandardError?
-
Attributes
__attributes__[R]
@!attribute [r] message
@return [String] the message related to the error
message[RW]
@!attribute [rw] message
@return [String] the message related to the error
@!attribute [rw] status
@return [String] the status code for the error response
status[RW]
@!attribute [rw] message
@return [String] the message related to the error
@!attribute [rw] status
@return [String] the status code for the error response
Public Class Methods
new(attributes = {})
click to toggle source
@param [Hash] attributes the key/value pairs to set instance variables
with
@option :message [String] the error's associated message @option :status [String] the error's associated status code @return [self] the {Controls::Error} with the given attributes
# 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
Public Instance Methods
inspect()
click to toggle source
@return [String] a string representing the error and all of it's
attributes
# 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()
click to toggle source
@return [Hash] the attributes used to initialize this error
# File lib/controls/objects/error.rb, line 40 def to_h @__attributes__ end
to_json()
click to toggle source
@return [String] the JSON representation of the attributes
# File lib/controls/objects/error.rb, line 35 def to_json @__attributes__.to_json end
to_s()
click to toggle source
@return [String] the error message if available otherwise calls {#inspect}
# File lib/controls/objects/error.rb, line 45 def to_s @message or inspect end