class Rack::MailExceptions

use smtp

use Rack::MailExceptions do |mail|
  mail.to 'test@gmail.com'
  mail.smtp :address => 'mail.test.com', :user_name => 'test@test.com', :password => 'test'
end

use sendmail

use Rack::MailExceptions do |mail|
  mail.to 'test@gmail.com'
  mail.smtp false
end

Constants

TEMPLATE

Attributes

config[R]

Public Instance Methods

call(env) click to toggle source
# File lib/rack/contrib/mailexceptions.rb, line 44
def call(env)
  status, headers, body =
    begin
      @app.call(env)
    rescue => boom
      send_notification boom, env
      raise
    end
  send_notification env['mail.exception'], env if env['mail.exception']
  [status, headers, body]
end
disable_test_mode() click to toggle source
# File lib/rack/contrib/mailexceptions.rb, line 72
def disable_test_mode
  @test_mode = false
end
enable_test_mode() click to toggle source
# File lib/rack/contrib/mailexceptions.rb, line 68
def enable_test_mode
  @test_mode = true
end
smtp(settings={}) click to toggle source
# File lib/rack/contrib/mailexceptions.rb, line 60
def smtp(settings={})
  if settings
    @config[:smtp].merge! settings
  else
    @config[:smtp] = nil
  end
end

Public Class Methods

new(app) { |self| ... } click to toggle source
# File lib/rack/contrib/mailexceptions.rb, line 24
def initialize(app)
  @app = app
  @config = {
    :to      => nil,
    :from    => ENV['USER'] || 'rack@localhost',
    :subject => '[exception] %s',
    :smtp    => {
      :address        => 'localhost',
      :domain         => 'localhost',
      :port           => 25,
      :authentication => :login,
      :user_name      => nil,
      :password       => nil
    }
  }
  @template = ERB.new(TEMPLATE)
  @test_mode = false
  yield self if block_given?
end