Class: RosettaQueue::ExceptionHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/rosetta_queue/exception_handler.rb

Class Method Summary collapse

Class Method Details

.define {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:



69
70
71
# File 'lib/rosetta_queue/exception_handler.rb', line 69

def define
  yield self
end

.handle(messaging_action = :all, info_or_proc = {}) ⇒ Object



59
60
61
62
63
64
65
66
# File 'lib/rosetta_queue/exception_handler.rb', line 59

def handle(messaging_action=:all, info_or_proc={})
  yield
rescue Exception => e
  handlers = handlers_for(messaging_action)
  raise e if handlers.empty?
  info = info_or_proc.respond_to?(:call) ? info_or_proc.call : info_or_proc
  handlers.each { |h| h.handle(e, info) }
end

.register(messaging_action, handler_klass = nil, &block) ⇒ Object Also known as: for



77
78
79
80
81
82
83
84
85
86
87
# File 'lib/rosetta_queue/exception_handler.rb', line 77

def register(messaging_action, handler_klass=nil, &block)
  handler = handler_klass
  if block_given?
    def block.handle(*args)
      call(*args)
    end
    handler = block
  end

  handlers[messaging_action] << handler
end

.reset_handlersObject



73
74
75
# File 'lib/rosetta_queue/exception_handler.rb', line 73

def reset_handlers
  @handlers = Hash.new { |h, k| h[k] = [] }
end