Class: ExceptionNotifier::BearychatNotifier

Inherits:
Object
  • Object
show all
Defined in:
lib/exception_notifier/bearychat_notifier.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ BearychatNotifier

Returns a new instance of BearychatNotifier.



8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/exception_notifier/bearychat_notifier.rb', line 8

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

    webhook_url = options.fetch(:webhook_url)
    options.delete(:webhook_url)
    @payload_options = options
    @payload_options[:attachments] = options.fetch(:attachments, [])
    @notifier = Bearychat::Notifier.new webhook_url, options
  rescue
    @notifier = nil
  end
end

Instance Attribute Details

#notifierObject

include ExceptionNotifier::BacktraceCleaner # 不在 exception_notification 手动添加代码过来



6
7
8
# File 'lib/exception_notifier/bearychat_notifier.rb', line 6

def notifier
  @notifier
end

Instance Method Details

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



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/exception_notifier/bearychat_notifier.rb', line 22

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

  text = enrich_message_with_data(text, options)

  attachment_options = {}
  attachment_options[:text] = enrich_message_with_backtrace(text, exception)
  @payload_options[:attachments].push(attachment_options)

  @notifier.ping(text, @payload_options) if valid?
end

#deep_reject(hash, block) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
# File 'lib/exception_notifier/bearychat_notifier.rb', line 41

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