Class: Safely::Strategy::Mail
- Inherits:
-
Object
- Object
- Safely::Strategy::Mail
- Defined in:
- lib/safely/strategy/mail.rb
Class Attribute Summary collapse
-
.recipient ⇒ Object
Recipient of the exception mails.
-
.sender ⇒ Object
The sender.
-
.subject_prefix ⇒ Object
Subject prefix.
Class Method Summary collapse
Class Attribute Details
.recipient ⇒ Object
Recipient of the exception mails
8 9 10 |
# File 'lib/safely/strategy/mail.rb', line 8 def recipient @recipient end |
.sender ⇒ Object
The sender
11 12 13 |
# File 'lib/safely/strategy/mail.rb', line 11 def sender @sender end |
.subject_prefix ⇒ Object
Subject prefix
14 15 16 |
# File 'lib/safely/strategy/mail.rb', line 14 def subject_prefix @subject_prefix end |
Class Method Details
.load! ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/safely/strategy/mail.rb', line 16 def load! begin require 'mail' rescue LoadError $stderr.write( "'mail' not available, safely cannot use the email stategy" ) end if self.sender.nil? require 'socket' self.sender = "safely@#{Socket.gethostname}" end self.subject_prefix ||= "[SAFELY]" end |
.report!(exception) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/safely/strategy/mail.rb', line 31 def report!( exception ) return if self.sender.nil? || self.recipient.nil? mail = ::Mail.new mail.from = self.sender mail.to = self.recipient mail.subject = "#{subject_prefix} - #{exception.}" mail.body = <<-EOF Safely caught an unhandled exception in your application, details below: Type: #{exception.class.name} Message: #{exception.} Backtrace: #{exception.backtrace.join("\n ")} EOF mail.deliver end |