class CronoTrigger::ExceptionHandler

Public Class Methods

handle_exception(record, ex) click to toggle source
# File lib/crono_trigger/exception_handler.rb, line 3
def self.handle_exception(record, ex)
  new(record).handle_exception(ex)
end
new(record) click to toggle source
# File lib/crono_trigger/exception_handler.rb, line 7
def initialize(record)
  @record = record
end

Public Instance Methods

handle_exception(ex) click to toggle source
# File lib/crono_trigger/exception_handler.rb, line 11
def handle_exception(ex)
  handlers = CronoTrigger.config.error_handlers + Array(@record.crono_trigger_options[:error_handlers])
  handlers.each do |callable|
    callable, arity = ensure_callable(callable)
    args = [ex, @record]
    args = arity < 0 ? args : args.take(arity)
    callable.call(*args)
  end
rescue Exception => e
  @record.logger.error("CronoTrigger error handler raises error")
  @record.logger.error(e)
end

Private Instance Methods

ensure_callable(callable) click to toggle source
# File lib/crono_trigger/exception_handler.rb, line 26
def ensure_callable(callable)
  if callable.respond_to?(:call)
    return callable, callable.arity
  elsif callable.is_a?(Symbol)
    return @record.method(callable), 1
  end
end