Class: Aesop::Dispatcher

Inherits:
Object
  • Object
show all
Includes:
Aesop, Singleton
Defined in:
lib/aesop/dispatcher.rb

Constant Summary

Constants included from Aesop

VERSION

Instance Method Summary collapse

Methods included from Aesop

#configuration, configuration

Constructor Details

#initializeDispatcher

Returns a new instance of Dispatcher.



11
12
13
# File 'lib/aesop/dispatcher.rb', line 11

def initialize
  collect_dispatchers
end

Instance Method Details

#collect_dispatchersObject



31
32
33
34
35
36
# File 'lib/aesop/dispatcher.rb', line 31

def collect_dispatchers
  configuration.dispatchers.each do |dispatch_symbol|
    instance = instantiate_dispatcher( dispatch_symbol )
    register_dispatcher(instance)
  end
end

#dispatch_exception(exception) ⇒ Object



15
16
17
18
19
20
21
22
23
24
# File 'lib/aesop/dispatcher.rb', line 15

def dispatch_exception(exception)
  dispatchers.each do |dispatcher|
    begin
      Aesop::Logger.debug("#{dispatcher.class.to_s}: dispatching #{exception.class.to_s}")
      dispatcher.dispatch_exception(exception)
    rescue => e
      Aesop::Logger.error( "Exception in #{dispatcher.class.to_s}: Exception: #{exception.class.to_s}. Trying to dispatch: #{e.class.to_s}: #{e.message}" )
    end
  end
end

#dispatchersObject



42
43
44
# File 'lib/aesop/dispatcher.rb', line 42

def dispatchers
  @dispatchers ||= []
end

#instantiate_dispatcher(symbol) ⇒ Object



26
27
28
29
# File 'lib/aesop/dispatcher.rb', line 26

def instantiate_dispatcher( symbol )
  Aesop::Logger.debug("Instantiating #{to_classname(symbol)}")
  Aesop::Dispatchers.const_get( to_classname(symbol) ).new
end

#register_dispatcher(dispatcher) ⇒ Object



38
39
40
# File 'lib/aesop/dispatcher.rb', line 38

def register_dispatcher( dispatcher )
  dispatchers << dispatcher
end

#to_classname(symbol) ⇒ Object



46
47
48
# File 'lib/aesop/dispatcher.rb', line 46

def to_classname(symbol)
  symbol.to_s.split(/[-_]/).map(&:capitalize).join
end