Class: ExceptionNotifier::EmailNotifier

Inherits:
BaseNotifier show all
Defined in:
lib/exception_notifier/email_notifier.rb

Defined Under Namespace

Modules: Mailer

Constant Summary collapse

DEFAULT_OPTIONS =
{
  sender_address: %("Exception Notifier" <[email protected]>),
  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,
  include_controller_and_action_names_in_subject: true,
  delivery_method: nil,
  mailer_settings: nil,
  email_headers: {},
  mailer_parent: 'ActionMailer::Base',
  template_path: 'exception_notifier',
  deliver_with: nil
}.freeze

Instance Attribute Summary

Attributes inherited from BaseNotifier

#base_options

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseNotifier

#_post_callback, #_pre_callback, #send_notice

Constructor Details

#initialize(options) ⇒ EmailNotifier

Returns a new instance of EmailNotifier.



158
159
160
161
162
163
164
165
166
# 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

Class Method Details

.normalize_digits(string) ⇒ Object



186
187
188
# File 'lib/exception_notifier/email_notifier.rb', line 186

def self.normalize_digits(string)
  string.gsub(/[0-9]+/, 'N')
end

Instance Method Details

#call(exception, options = {}) ⇒ Object



168
169
170
171
172
# 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 = {}) ⇒ Object



174
175
176
177
178
179
180
181
182
183
184
# 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