Class: ExceptionNotifier::SlackNotifier

Inherits:
BaseNotifier show all
Includes:
BacktraceCleaner
Defined in:
lib/exception_notifier/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
# File 'lib/exception_notifier/slack_notifier.rb', line 9

def initialize(options)
  super
  begin
    @ignore_data_if = options[:ignore_data_if]
    @backtrace_lines = options.fetch(:backtrace_lines, 10)
    @additional_fields = options[:additional_fields]

    webhook_url = options.fetch(:webhook_url)
    @message_opts = options.fetch(:additional_parameters, {})
    @color = @message_opts.delete(:color) { 'danger' }
    @notifier = Slack::Notifier.new webhook_url, options
  rescue StandardError
    @notifier = nil
  end
end

Instance Attribute Details

#notifierObject

Returns the value of attribute notifier.



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

def notifier
  @notifier
end

Instance Method Details

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



25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/exception_notifier/slack_notifier.rb', line 25

def call(exception, options = {})
  clean_message = exception.message.tr('`', "'")
  attchs = attchs(exception, clean_message, options)

  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