Class: EndpointFlux::Config::RescueFrom

Inherits:
Object
  • Object
show all
Defined in:
lib/endpoint_flux/config/rescue_from.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRescueFrom

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

#exceptionsObject

Returns the value of attribute exceptions.



4
5
6
# File 'lib/endpoint_flux/config/rescue_from.rb', line 4

def exceptions
  @exceptions
end

#handlersObject

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