class Isolator::Notifier

Wrapper over different notifications methods (exceptions, logging, uniform notifier)

Attributes

backtrace[R]
exception[R]

Public Class Methods

new(exception, backtrace = caller) click to toggle source
# File lib/isolator/notifier.rb, line 8
def initialize(exception, backtrace = caller)
  @exception = exception
  @backtrace = backtrace
end

Public Instance Methods

call() click to toggle source
# File lib/isolator/notifier.rb, line 13
def call
  log_exception
  send_notifications if send_notifications?
  raise(exception.class, exception.message, filtered_backtrace) if raise_exceptions?
end

Private Instance Methods

filtered_backtrace() click to toggle source
# File lib/isolator/notifier.rb, line 50
def filtered_backtrace
  Isolator.config.backtrace_filter.call(backtrace)
end
log_exception() click to toggle source
# File lib/isolator/notifier.rb, line 29
def log_exception
  return unless Isolator.config.logger

  offense_line = filtered_backtrace.first

  msg = "[ISOLATOR EXCEPTION]\n" \
        "#{exception.message}"

  msg += "\n  ↳ #{offense_line}" if offense_line

  Isolator.config.logger.warn(msg)
end
raise_exceptions?() click to toggle source
# File lib/isolator/notifier.rb, line 21
def raise_exceptions?
  Isolator.config.raise_exceptions?
end
send_notifications() click to toggle source
# File lib/isolator/notifier.rb, line 42
def send_notifications
  return unless uniform_notifier_loaded?

  ::UniformNotifier.active_notifiers.each do |notifier|
    notifier.out_of_channel_notify exception.message
  end
end
send_notifications?() click to toggle source
# File lib/isolator/notifier.rb, line 25
def send_notifications?
  Isolator.config.send_notifications?
end
uniform_notifier_loaded?() click to toggle source
# File lib/isolator/notifier.rb, line 54
def uniform_notifier_loaded?
  return true if defined?(::UniformNotifier)

  begin
    require "uniform_notifier"
  rescue LoadError
    warn(
      "Please, install and configure 'uniform_notifier' to send notifications:\n" \
      "# Gemfile\n" \
      "gem 'uniform_notifer', '~> 1.11', require: false"
    )
  end
end