Module: Roda::RodaPlugins::ErrorEmail::InstanceMethods
- Defined in:
- lib/roda/plugins/error_email.rb
Instance Method Summary collapse
-
#error_email(exception) ⇒ Object
Send an email for the given error.
-
#error_email_content(exception) ⇒ Object
The content of the email to send, include the headers and the body.
Instance Method Details
#error_email(exception) ⇒ Object
Send an email for the given error. exception
is usually an exception instance, but it can be a plain string which is used as the subject for the email.
115 116 117 118 119 |
# File 'lib/roda/plugins/error_email.rb', line 115 def error_email(exception) email_opts = self.class.opts[:error_email].dup email_opts[:message] = error_email_content(exception) email_opts[:emailer].call(email_opts) end |
#error_email_content(exception) ⇒ Object
The content of the email to send, include the headers and the body. Takes the same argument as #error_email.
123 124 125 126 127 128 129 130 |
# File 'lib/roda/plugins/error_email.rb', line 123 def error_email_content(exception) email_opts = self.class.opts[:error_email] headers = email_opts[:default_headers].call(email_opts, exception) headers = Hash[headers].merge!(email_opts[:headers]) headers = headers.map{|k,v| "#{k}: #{v.gsub(/\r?\n/m, "\r\n ")}"}.sort.join("\r\n") body = email_opts[:body].call(self, exception) "#{headers}\r\n\r\n#{body}" end |