Class: Dreamcatcher::Monitor

Inherits:
Object
  • Object
show all
Defined in:
lib/dreamcatcher/monitor.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(configuration) ⇒ Monitor

Returns a new instance of Monitor.



5
6
7
8
# File 'lib/dreamcatcher/monitor.rb', line 5

def initialize(configuration)
  @configuration = configuration
  @handlers = build_handlers
end

Instance Attribute Details

#configurationObject (readonly)

Returns the value of attribute configuration.



3
4
5
# File 'lib/dreamcatcher/monitor.rb', line 3

def configuration
  @configuration
end

#handlersObject (readonly)

Returns the value of attribute handlers.



3
4
5
# File 'lib/dreamcatcher/monitor.rb', line 3

def handlers
  @handlers
end

Instance Method Details

#monitor(options = {}, &block) ⇒ Object



10
11
12
13
14
15
16
17
18
19
# File 'lib/dreamcatcher/monitor.rb', line 10

def monitor(options = {}, &block)
  @context = options[:context] || {}
  logger_proxy = Dreamcatcher::LoggerProxy.new(options[:logger])
  logger_proxy.capture { block.call }
    
rescue @configuration.exception_class => exception
  context = Dreamcatcher::ExceptionContext.new(exception, logger_proxy.log_entries)
  handlers.each { |handler| handler.handle_exception(context) }
  raise 
end