class ExceptionNotifier::EmailNotifier

Constants

DEFAULT_OPTIONS

Public Class Methods

new(options) click to toggle source
Calls superclass method ExceptionNotifier::BaseNotifier::new
# File lib/exception_notifier/email_notifier.rb, line 158
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)

  @base_options = DEFAULT_OPTIONS.merge(options)
end
normalize_digits(string) click to toggle source
# File lib/exception_notifier/email_notifier.rb, line 186
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 168
def call(exception, options = {})
  message = create_email(exception, options)

  message.send(base_options[:deliver_with] || default_deliver_with(message))
end
create_email(exception, options = {}) click to toggle source
# File lib/exception_notifier/email_notifier.rb, line 174
def create_email(exception, options = {})
  env = options[:env]

  send_notice(exception, options, nil, base_options) do |_, default_opts|
    if env.nil?
      mailer.background_exception_notification(exception, options, default_opts)
    else
      mailer.exception_notification(env, exception, options, default_opts)
    end
  end
end

Private Instance Methods

default_deliver_with(message) click to toggle source
# File lib/exception_notifier/email_notifier.rb, line 199
def default_deliver_with(message)
  # FIXME: use `if Gem::Version.new(ActionMailer::VERSION::STRING) < Gem::Version.new('4.1')`
  message.respond_to?(:deliver_now) ? :deliver_now : :deliver
end
mailer() click to toggle source
# File lib/exception_notifier/email_notifier.rb, line 192
def mailer
  @mailer ||= Class.new(base_options[:mailer_parent].constantize).tap do |mailer|
    mailer.extend(EmailNotifier::Mailer)
    mailer.mailer_name = base_options[:template_path]
  end
end