Class: EndpointFlux::Config::RescueFrom
- Inherits:
-
Object
- Object
- EndpointFlux::Config::RescueFrom
- Defined in:
- lib/endpoint_flux/config/rescue_from.rb
Instance Attribute Summary collapse
-
#exceptions ⇒ Object
Returns the value of attribute exceptions.
-
#handlers ⇒ Object
Returns the value of attribute handlers.
Instance Method Summary collapse
- #add(klass, &block) ⇒ Object
-
#initialize ⇒ RescueFrom
constructor
A new instance of RescueFrom.
- #run(name, attrs, e) ⇒ Object
Constructor Details
#initialize ⇒ RescueFrom
Returns a new instance of RescueFrom.
6 7 8 9 |
# File 'lib/endpoint_flux/config/rescue_from.rb', line 6 def initialize @handlers = {} @exceptions = [] end |
Instance Attribute Details
#exceptions ⇒ Object
Returns the value of attribute exceptions.
4 5 6 |
# File 'lib/endpoint_flux/config/rescue_from.rb', line 4 def exceptions @exceptions end |
#handlers ⇒ Object
Returns the value of attribute handlers.
4 5 6 |
# File 'lib/endpoint_flux/config/rescue_from.rb', line 4 def handlers @handlers end |
Instance Method Details
#add(klass, &block) ⇒ Object
17 18 19 20 21 22 23 24 25 |
# File 'lib/endpoint_flux/config/rescue_from.rb', line 17 def add(klass, &block) raise 'Block not given' unless block_given? handlers[klass.to_s] = block exceptions << klass unless exceptions.include?(klass) nil end |
#run(name, attrs, e) ⇒ Object
11 12 13 14 15 |
# File 'lib/endpoint_flux/config/rescue_from.rb', line 11 def run(name, attrs, e) raise 'No handler given' unless exceptions.include?(e.class) handlers[e.class.name].call(name, attrs, e) end |