lib/roda/plugins/error_mail.rb
# 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.
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.
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 .
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}"
          format = lambda{|h| h.map{|k, v| "#{k.inspect} => #{v.inspect}"}.sort.join("\n")}
          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
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}" format = lambda { | h | h . map { | k , v | "#{k.inspect} => #{v.inspect}" } . sort . join ( "\n" ) } 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
Send an email for the given error.
Send an email for the given error .
e