Class: Jsapi::Meta::RescueHandler
- Inherits:
-
Base::Model
- Object
- Base::Model
- Jsapi::Meta::RescueHandler
- Defined in:
- lib/jsapi/meta/rescue_handler.rb
Overview
Maps an error class to a response status.
Constant Summary
Constants included from Base::Attributes
Base::Attributes::DEFAULT_ARRAY, Base::Attributes::DEFAULT_HASH
Instance Method Summary collapse
-
#error_class ⇒ Object
:attr: error_class The error class to be mapped.
-
#initialize(keywords = {}) ⇒ RescueHandler
constructor
A new instance of RescueHandler.
-
#match?(exception) ⇒ Boolean
Returns true if
exception
is an instance of the class to be mapped, false otherwise. -
#status ⇒ Object
:attr: status The response status.
Methods inherited from Base::Model
#inspect, #merge!, #reference?, #resolve
Methods included from Base::Attributes
Constructor Details
#initialize(keywords = {}) ⇒ RescueHandler
Returns a new instance of RescueHandler.
17 18 19 20 21 22 23 24 25 |
# File 'lib/jsapi/meta/rescue_handler.rb', line 17 def initialize(keywords = {}) super unless error_class.is_a?(Class) raise ArgumentError, "#{error_class.inspect} isn't a class" end unless error_class <= StandardError raise ArgumentError, "#{error_class.inspect} isn't a rescuable class" end end |
Instance Method Details
#error_class ⇒ Object
:attr: error_class The error class to be mapped.
10 |
# File 'lib/jsapi/meta/rescue_handler.rb', line 10 attribute :error_class, default: StandardError |
#match?(exception) ⇒ Boolean
Returns true if exception
is an instance of the class to be mapped, false otherwise.
28 29 30 |
# File 'lib/jsapi/meta/rescue_handler.rb', line 28 def match?(exception) exception.is_a?(error_class) end |
#status ⇒ Object
:attr: status The response status. The default is "default"
.
15 |
# File 'lib/jsapi/meta/rescue_handler.rb', line 15 attribute :status, default: 'default' |