Class: ExceptionNotifier::Rake

Inherits:
Object
  • Object
show all
Defined in:
lib/exception_notifier/rake/rake.rb,
lib/exception_notifier/rake/version.rb

Constant Summary collapse

VERSION =
'0.0.6'

Class Method Summary collapse

Class Method Details

.configure(options = {}) ⇒ Object

Configure Rake exception notifications. Should be called in a config file, usually in config/environments/production.rb for production use. An optional hash of options can be given, which will be passed through unchanged to the underlying ExceptionNotifier.



21
22
23
24
# File 'lib/exception_notifier/rake/rake.rb', line 21

def self.configure(options = {})
  @notifier_options.merge!(default_notifier_options)
  @notifier_options.merge!(options)
end

.configured?Boolean

Whether Rake exception notifications have been configured.

Returns:

  • (Boolean)


13
14
15
# File 'lib/exception_notifier/rake/rake.rb', line 13

def self.configured?
  !@notifier_options.empty?
end

.default_notifier_optionsObject



26
27
28
29
30
# File 'lib/exception_notifier/rake/rake.rb', line 26

def self.default_notifier_options
  {
    :background_sections => %w(rake backtrace),
  }
end

.maybe_deliver_notification(exception, data = {}) ⇒ Object

Deliver a notification about the given exception by email, in case notifications have been configured. The additional data hash will be passed through to ExceptionNotifier’s data hash and will be availble in templates.



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/exception_notifier/rake/rake.rb', line 40

def self.maybe_deliver_notification(exception, data={})
  if configured?
    options = notifier_options
    if conditionally_ignored(options[:ignore_if], exception) ||
        ignored_exception(options[:ignore_exceptions], exception)
      return
    end

    if !data.empty?
      options = options.dup
      options[:data] = data.merge(options[:data] || {})
    end
    ExceptionNotifier::Notifier.background_exception_notification(
      exception, options).deliver
  end
end

.notifier_optionsObject



32
33
34
# File 'lib/exception_notifier/rake/rake.rb', line 32

def self.notifier_options
  @notifier_options
end

.reset_for_testObject



57
58
59
# File 'lib/exception_notifier/rake/rake.rb', line 57

def self.reset_for_test
  @notifier_options = {}
end