class ExceptionNotifier::IrcNotifier

Public Class Methods

new(options) click to toggle source
Calls superclass method ExceptionNotifier::BaseNotifier.new
# File lib/exception_notifier/irc_notifier.rb, line 3
def initialize(options)
  super
  @config = OpenStruct.new
  parse_options(options)
end

Public Instance Methods

call(exception, options={}) click to toggle source
# File lib/exception_notifier/irc_notifier.rb, line 9
def call(exception, options={})
  message = "'#{exception.message}'"
  message += " on '#{exception.backtrace.first}'" if exception.backtrace
  if active?
    send_notice(exception, options, message) do |msg, _|
      send_message([*@config.prefix, *msg].join(' '))
    end
  end
end
send_message(message) click to toggle source
# File lib/exception_notifier/irc_notifier.rb, line 19
def send_message(message)
  CarrierPigeon.send @config.irc.merge({message: message})
end

Private Instance Methods

active?() click to toggle source
# File lib/exception_notifier/irc_notifier.rb, line 41
def active?
  valid_uri? @config.irc[:uri]
end
parse_options(options) click to toggle source
# File lib/exception_notifier/irc_notifier.rb, line 24
def parse_options(options)
  nick = options.fetch(:nick, 'ExceptionNotifierBot')
  password = options[:password] ? ":#{options[:password]}" : nil
  domain = options.fetch(:domain, nil)
  port = options[:port] ? ":#{options[:port]}" : nil
  channel = options.fetch(:channel, '#log')
  notice = options.fetch(:notice, false)
  ssl = options.fetch(:ssl, false)
  join = options.fetch(:join, false)
  uri = "irc://#{nick}#{password}@#{domain}#{port}/#{channel}"
  prefix = options.fetch(:prefix, nil)
  recipients = options[:recipients] ? options[:recipients].join(', ') + ':' : nil

  @config.prefix = [*prefix, *recipients].join(' ')
  @config.irc = { uri: uri, ssl: ssl, notice: notice, join: join }
end
valid_uri?(uri) click to toggle source
# File lib/exception_notifier/irc_notifier.rb, line 45
def valid_uri?(uri)
  !!URI.parse(uri)
rescue URI::InvalidURIError
  false
end