Class: ExceptionNotifier::IrcNotifier

Inherits:
BaseNotifier show all
Defined in:
lib/exception_notifier/irc_notifier.rb

Instance Attribute Summary

Attributes inherited from BaseNotifier

#base_options

Instance Method Summary collapse

Methods inherited from BaseNotifier

#_post_callback, #_pre_callback, #send_notice

Constructor Details

#initialize(options) ⇒ IrcNotifier

Returns a new instance of IrcNotifier.



5
6
7
8
9
# File 'lib/exception_notifier/irc_notifier.rb', line 5

def initialize(options)
  super
  @config = OpenStruct.new
  parse_options(options)
end

Instance Method Details

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



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/exception_notifier/irc_notifier.rb', line 11

def call(exception, options = {})
  errors_count = options[:accumulated_errors_count].to_i

  occurrences = "(#{errors_count} times)" if errors_count > 1
  message = "#{occurrences}'#{exception.message}'"
  message += " on '#{exception.backtrace.first}'" if exception.backtrace

  return unless active?

  send_notice(exception, options, message) do |msg, _|
    send_message([*@config.prefix, *msg].join(' '))
  end
end

#send_message(message) ⇒ Object



25
26
27
# File 'lib/exception_notifier/irc_notifier.rb', line 25

def send_message(message)
  CarrierPigeon.send @config.irc.merge(message: message)
end