Sha256: 160a8190b8712ac6cf2caddcd5fe46512bd817a4e29ad7a377976789efb33094

Contents?: true

Size: 1.06 KB

Versions: 1

Compression:

Stored size: 1.06 KB

Contents

module ExceptionNotifier
  class CampfireNotifier < BaseNotifier
    attr_accessor :subdomain
    attr_accessor :token
    attr_accessor :room

    def initialize(options)
      super
      begin
        subdomain = options.delete(:subdomain)
        room_name = options.delete(:room_name)
        @campfire = Tinder::Campfire.new subdomain, options
        @room     = @campfire.find_room_by_name room_name
      rescue StandardError
        @campfire = @room = nil
      end
    end

    def call(exception, options = {})
      return unless active?

      message = if options[:accumulated_errors_count].to_i > 1
                  "The exception occurred #{options[:accumulated_errors_count]} times: '#{exception.message}'"
                else
                  "A new exception occurred: '#{exception.message}'"
                end
      message += " on '#{exception.backtrace.first}'" if exception.backtrace
      send_notice(exception, options, message) do |msg, _|
        @room.paste msg
      end
    end

    private

    def active?
      !@room.nil?
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
exception_notification-4.4.0 lib/exception_notifier/campfire_notifier.rb