module Roda::RodaPlugins::ErrorMail::InstanceMethods
Public Instance Methods
Source
# File lib/roda/plugins/error_mail.rb, line 57 def error_mail(exception) _error_mail(exception).deliver! end
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.
Source
# File lib/roda/plugins/error_mail.rb, line 63 def error_mail_content(exception) _error_mail(exception).to_s end
The content of the email to send, include the headers and the body. Takes the same argument as error_mail
.
Private Instance Methods
Source
# File lib/roda/plugins/error_mail.rb, line 69 def _error_mail(e) email_opts = self.class.opts[:error_mail] subject = if e.respond_to?(:message) "#{e.class}: #{e.message}" else e.to_s end subject = "#{email_opts[:prefix]}#{subject}" filter = email_opts[:filter] format = lambda do |h| h = h.map{|k, v| "#{k.inspect} => #{filter.call(k, v) ? 'FILTERED' : v.inspect}"} h.sort! h.join("\n") end begin params = request.params params = (format[params] unless params.empty?) rescue params = 'Invalid Parameters!' end message = String.new message << <<END Path: #{request.path} END if e.respond_to?(:backtrace) message << <<END Backtrace: #{e.backtrace.join("\n")} END end message << <<END ENV: #{format[env]} END if params message << <<END Params: #{params} END end if env['rack.session'] message << <<END Session: #{format[session]} END end Mail.new do from email_opts[:from] to email_opts[:to] subject subject body message if headers = email_opts[:headers] headers.each do |k,v| header[k] = v end end end end