Class: ExceptionNotifier::Notifier
- Inherits:
-
ActionMailer::Base
- Object
- ActionMailer::Base
- ExceptionNotifier::Notifier
show all
- Defined in:
- lib/exception_notifier/notifier.rb
Defined Under Namespace
Classes: MissingController
Class Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Class Attribute Details
.default_email_prefix ⇒ Object
26
27
28
|
# File 'lib/exception_notifier/notifier.rb', line 26
def default_email_prefix
@default_email_prefix || "[ERROR] "
end
|
.default_exception_recipients ⇒ Object
22
23
24
|
# File 'lib/exception_notifier/notifier.rb', line 22
def default_exception_recipients
@default_exception_recipients || []
end
|
.default_sections ⇒ Object
30
31
32
|
# File 'lib/exception_notifier/notifier.rb', line 30
def default_sections
@default_sections || %w(request session environment backtrace)
end
|
.default_sender_address ⇒ Object
18
19
20
|
# File 'lib/exception_notifier/notifier.rb', line 18
def default_sender_address
@default_sender_address || %("Exception Notifier" <[email protected]>)
end
|
Class Method Details
.default_options ⇒ Object
34
35
36
37
38
39
|
# File 'lib/exception_notifier/notifier.rb', line 34
def default_options
{ :sender_address => default_sender_address,
:exception_recipients => default_exception_recipients,
:email_prefix => default_email_prefix,
:sections => default_sections }
end
|
Instance Method Details
#background_exception_notification(exception) ⇒ Object
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
# File 'lib/exception_notifier/notifier.rb', line 70
def background_exception_notification(exception)
if @notifier = Rails.application.config.middleware.detect{ |x| x.klass == ExceptionNotifier }
@options = (@notifier.args.first || {}).reverse_merge(self.class.default_options)
subject = "#{@options[:email_prefix]} (#{exception.class}) #{exception.message.inspect}"
@exception = exception
@backtrace = exception.backtrace || []
@sections = %w{backtrace}
mail(:to => @options[:exception_recipients], :from => @options[:sender_address], :subject => subject) do |format|
format.text { render "#{mailer_name}/background_exception_notification" }
end.deliver
end
end
|
#exception_notification(env, exception) ⇒ Object
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
# File 'lib/exception_notifier/notifier.rb', line 47
def exception_notification(env, exception)
@env = env
@exception = exception
@options = (env['exception_notifier.options'] || {}).reverse_merge(self.class.default_options)
@kontroller = env['action_controller.instance'] || MissingController.new
@request = ActionDispatch::Request.new(env)
@backtrace = clean_backtrace(exception)
@sections = @options[:sections]
data = env['exception_notifier.exception_data'] || {}
data.each do |name, value|
instance_variable_set("@#{name}", value)
end
prefix = "#{@options[:email_prefix]}#{@kontroller.controller_name}##{@kontroller.action_name}"
subject = "#{prefix} (#{@exception.class}) #{@exception.message.inspect}"
subject = subject.length > 120 ? subject[0...120] + "..." : subject
mail(:to => @options[:exception_recipients], :from => @options[:sender_address], :subject => subject) do |format|
format.text { render "#{mailer_name}/exception_notification" }
end
end
|