forked from rails/exception_notification
-
Notifications
You must be signed in to change notification settings - Fork 414
/
campfire_notifier.rb
39 lines (35 loc) · 1.07 KB
/
campfire_notifier.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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 = {})
if 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
end
private
def active?
!@room.nil?
end
end
end