class ExceptionNotifier::EmailNotifier

Attributes

background_sections[RW]
deliver_with[RW]
delivery_method[RW]
email_format[RW]
email_headers[RW]
email_prefix[RW]
exception_recipients[RW]
mailer_parent[RW]
mailer_settings[RW]
normalize_subject[RW]
post_callback[RW]
pre_callback[RW]
sections[RW]
sender_address[RW]
template_path[RW]
verbose_subject[RW]

Public Class Methods

default_options() click to toggle source
# File lib/exception_notifier/email_notifier.rb, line 190
def self.default_options
  {
    :sender_address => %Q("Exception Notifier" <exception.notifier@example.com>),
    :exception_recipients => [],
    :email_prefix => "[ERROR] ",
    :email_format => :text,
    :sections => %w(request session environment backtrace),
    :background_sections => %w(backtrace data),
    :verbose_subject => true,
    :normalize_subject => false,
    :delivery_method => nil,
    :mailer_settings => nil,
    :email_headers => {},
    :mailer_parent => 'ActionMailer::Base',
    :template_path => 'exception_notifier',
    :deliver_with => :default
  }
end
new(options) click to toggle source
Calls superclass method ExceptionNotifier::BaseNotifier.new
# File lib/exception_notifier/email_notifier.rb, line 134
def initialize(options)
  super
  delivery_method = (options[:delivery_method] || :smtp)
  mailer_settings_key = "#{delivery_method}_settings".to_sym
  options[:mailer_settings] = options.delete(mailer_settings_key)

  options.reverse_merge(EmailNotifier.default_options).select{|k,v|[
    :sender_address, :exception_recipients,
    :pre_callback, :post_callback,
    :email_prefix, :email_format, :sections, :background_sections,
    :verbose_subject, :normalize_subject, :delivery_method, :mailer_settings,
    :email_headers, :mailer_parent, :template_path, :deliver_with].include?(k)}.each{|k,v| send("#{k}=", v)}
end
normalize_digits(string) click to toggle source
# File lib/exception_notifier/email_notifier.rb, line 209
def self.normalize_digits(string)
  string.gsub(/[0-9]+/, 'N')
end

Public Instance Methods

call(exception, options={}) click to toggle source
# File lib/exception_notifier/email_notifier.rb, line 161
def call(exception, options={})
  message = create_email(exception, options)

  # FIXME: use `if Gem::Version.new(ActionMailer::VERSION::STRING) < Gem::Version.new('4.1')`
  if deliver_with == :default
    if message.respond_to?(:deliver_now)
      message.deliver_now
    else
      message.deliver
    end
  else
    message.send(deliver_with)
  end
end
create_email(exception, options={}) click to toggle source
# File lib/exception_notifier/email_notifier.rb, line 176
def create_email(exception, options={})
  env = options[:env]
  default_options = self.options
  if env.nil?
    send_notice(exception, options, nil, default_options) do |_, default_opts|
      mailer.background_exception_notification(exception, options, default_opts)
    end
  else
    send_notice(exception, options, nil, default_options) do |_, default_opts|
      mailer.exception_notification(env, exception, options, default_opts)
    end
  end
end
mailer() click to toggle source
# File lib/exception_notifier/email_notifier.rb, line 154
def mailer
  @mailer ||= Class.new(mailer_parent.constantize).tap do |mailer|
    mailer.extend(EmailNotifier::Mailer)
    mailer.mailer_name = template_path
  end
end
options() click to toggle source
# File lib/exception_notifier/email_notifier.rb, line 148
def options
  @options ||= {}.tap do |opts|
    self.instance_variables.each { |var| opts[var[1..-1].to_sym] = self.instance_variable_get(var) }
  end
end