Class: ExceptionNotifier::EmailNotifier

Inherits:
Struct
  • Object
show all
Defined in:
lib/exception_notifier/email_notifier.rb

Defined Under Namespace

Modules: Mailer

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ EmailNotifier

Returns a new instance of EmailNotifier.



120
121
122
123
124
125
126
127
128
129
130
# File 'lib/exception_notifier/email_notifier.rb', line 120

def initialize(options)
  delivery_method = (options[:delivery_method] || :smtp)
  mailer_settings_key = "#{delivery_method}_settings".to_sym
  options[:mailer_settings] = options.delete(mailer_settings_key)

  super(*options.reverse_merge(EmailNotifier.default_options).values_at(
    :sender_address, :exception_recipients,
    :email_prefix, :email_format, :sections, :background_sections,
    :verbose_subject, :normalize_subject, :delivery_method, :mailer_settings,
    :email_headers, :mailer_parent, :template_path))
end

Instance Attribute Details

#background_sectionsObject

Returns the value of attribute background_sections

Returns:

  • (Object)

    the current value of background_sections



6
7
8
# File 'lib/exception_notifier/email_notifier.rb', line 6

def background_sections
  @background_sections
end

#delivery_methodObject

Returns the value of attribute delivery_method

Returns:

  • (Object)

    the current value of delivery_method



6
7
8
# File 'lib/exception_notifier/email_notifier.rb', line 6

def delivery_method
  @delivery_method
end

#email_formatObject

Returns the value of attribute email_format

Returns:

  • (Object)

    the current value of email_format



6
7
8
# File 'lib/exception_notifier/email_notifier.rb', line 6

def email_format
  @email_format
end

#email_headersObject

Returns the value of attribute email_headers

Returns:

  • (Object)

    the current value of email_headers



6
7
8
# File 'lib/exception_notifier/email_notifier.rb', line 6

def email_headers
  @email_headers
end

#email_prefixObject

Returns the value of attribute email_prefix

Returns:

  • (Object)

    the current value of email_prefix



6
7
8
# File 'lib/exception_notifier/email_notifier.rb', line 6

def email_prefix
  @email_prefix
end

#exception_recipientsObject

Returns the value of attribute exception_recipients

Returns:

  • (Object)

    the current value of exception_recipients



6
7
8
# File 'lib/exception_notifier/email_notifier.rb', line 6

def exception_recipients
  @exception_recipients
end

#mailer_parentObject

Returns the value of attribute mailer_parent

Returns:

  • (Object)

    the current value of mailer_parent



6
7
8
# File 'lib/exception_notifier/email_notifier.rb', line 6

def mailer_parent
  @mailer_parent
end

#mailer_settingsObject

Returns the value of attribute mailer_settings

Returns:

  • (Object)

    the current value of mailer_settings



6
7
8
# File 'lib/exception_notifier/email_notifier.rb', line 6

def mailer_settings
  @mailer_settings
end

#normalize_subjectObject

Returns the value of attribute normalize_subject

Returns:

  • (Object)

    the current value of normalize_subject



6
7
8
# File 'lib/exception_notifier/email_notifier.rb', line 6

def normalize_subject
  @normalize_subject
end

#sectionsObject

Returns the value of attribute sections

Returns:

  • (Object)

    the current value of sections



6
7
8
# File 'lib/exception_notifier/email_notifier.rb', line 6

def sections
  @sections
end

#sender_addressObject

Returns the value of attribute sender_address

Returns:

  • (Object)

    the current value of sender_address



6
7
8
# File 'lib/exception_notifier/email_notifier.rb', line 6

def sender_address
  @sender_address
end

#template_pathObject

Returns the value of attribute template_path

Returns:

  • (Object)

    the current value of template_path



6
7
8
# File 'lib/exception_notifier/email_notifier.rb', line 6

def template_path
  @template_path
end

#verbose_subjectObject

Returns the value of attribute verbose_subject

Returns:

  • (Object)

    the current value of verbose_subject



6
7
8
# File 'lib/exception_notifier/email_notifier.rb', line 6

def verbose_subject
  @verbose_subject
end

Class Method Details

.default_optionsObject



159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
# File 'lib/exception_notifier/email_notifier.rb', line 159

def self.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,
    :delivery_method => nil,
    :mailer_settings => nil,
    :email_headers => {},
    :mailer_parent => 'ActionMailer::Base',
    :template_path => 'exception_notifier'
  }
end

.normalize_digits(string) ⇒ Object



177
178
179
# File 'lib/exception_notifier/email_notifier.rb', line 177

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

Instance Method Details

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



145
146
147
# File 'lib/exception_notifier/email_notifier.rb', line 145

def call(exception, options={})
  create_email(exception, options).deliver
end

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



149
150
151
152
153
154
155
156
157
# File 'lib/exception_notifier/email_notifier.rb', line 149

def create_email(exception, options={})
  env = options[:env]
  default_options = self.options
  if env.nil?
    mailer.background_exception_notification(exception, options, default_options)
  else
    mailer.exception_notification(env, exception, options, default_options)
  end
end

#mailerObject



138
139
140
141
142
143
# File 'lib/exception_notifier/email_notifier.rb', line 138

def mailer
  @mailer ||= Class.new(mailer_parent.constantize).tap do |mailer|
    mailer.extend(EmailNotifier::Mailer)
    mailer.mailer_name = template_path
  end
end

#optionsObject



132
133
134
135
136
# File 'lib/exception_notifier/email_notifier.rb', line 132

def options
  @options ||= {}.tap do |opts|
    each_pair { |k,v| opts[k] = v }
  end
end