Class: Exceptify::SlackNotifier

Inherits:
BaseNotifier show all
Includes:
BacktraceCleaner
Defined in:
lib/exceptify/slack_notifier.rb

Instance Attribute Summary collapse

Attributes inherited from BaseNotifier

#base_options

Instance Method Summary collapse

Methods included from BacktraceCleaner

#clean_backtrace

Methods inherited from BaseNotifier

#_post_callback, #_pre_callback, #send_notice

Constructor Details

#initialize(options) ⇒ SlackNotifier

Returns a new instance of SlackNotifier.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/exceptify/slack_notifier.rb', line 9

def initialize(options)
  options = options.dup
  fail_silently = options.delete(:fail_silently) { false }
  injected_notifier = options.delete(:notifier)
  super()
  self.base_options = options

  @ignore_data_if = options[:ignore_data_if]
  @backtrace_lines = options.fetch(:backtrace_lines, 10)
  @additional_fields = options[:additional_fields]
  @message_opts = options.fetch(:additional_parameters, {}).dup
  @color = @message_opts.delete(:color) { "danger" }

  @notifier = injected_notifier || build_notifier(options)
rescue => e
  raise unless fail_silently

  log_configuration_error(e)
  @notifier = nil
end

Instance Attribute Details

#notifierObject

Returns the value of attribute notifier.



7
8
9
# File 'lib/exceptify/slack_notifier.rb', line 7

def notifier
  @notifier
end

Instance Method Details

#call(exception, options = {}) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/exceptify/slack_notifier.rb', line 30

def call(exception, options = {})
  notification = Notification.new(exception, options, backtrace_cleaner: self)
  clean_message = exception.message.tr("`", "'")
  attchs = attchs(notification, clean_message)

  return unless valid?

  args = [exception, options, clean_message, @message_opts.merge(attachments: attchs)]
  send_notice(*args) do |_msg, message_opts|
    message_opts[:channel] = options[:channel] if options.key?(:channel)

    @notifier.ping "", message_opts
  end
end