Class: ExceptionNotifier::SlackNotifier

Inherits:
Object
  • Object
show all
Includes:
BacktraceCleaner
Defined in:
lib/exception_notifier/slack_notifier.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from BacktraceCleaner

#clean_backtrace

Constructor Details

#initialize(options) ⇒ SlackNotifier

Returns a new instance of SlackNotifier.



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/exception_notifier/slack_notifier.rb', line 7

def initialize(options)
  begin
    @ignore_data_if = options[:ignore_data_if]

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

Instance Attribute Details

#notifierObject

Returns the value of attribute notifier.



5
6
7
# File 'lib/exception_notifier/slack_notifier.rb', line 5

def notifier
  @notifier
end

Instance Method Details

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



19
20
21
22
23
24
25
26
# File 'lib/exception_notifier/slack_notifier.rb', line 19

def call(exception, options={})
  message = "An exception occurred: '#{exception.message}' on '#{exception.backtrace.first}'"

  message = enrich_message_with_data(message, options)
  message = enrich_message_with_backtrace(message, exception)

  @notifier.ping(message, @message_opts) if valid?
end

#deep_reject(hash, block) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
# File 'lib/exception_notifier/slack_notifier.rb', line 35

def deep_reject(hash, block)
  hash.each do |k, v|
    if v.is_a?(Hash)
      deep_reject(v, block)
    end

    if block.call(k, v)
      hash.delete(k)
    end
  end
end