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.3.1'

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 notifiers.



19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/exception_notifier/rake/rake.rb', line 19

def self.configure(options = {})
  @configured = true
  @notifier_options.merge!(options)

  # There is only a single static list registered ignore_ifs. We make
  # ignore_ifs passed to just this configuration only effective for
  # background exceptions (the enviornment will be nil). That's the
  # best we can do, there isn't really a way to identify just our exceptions.
  if options[:ignore_if]
    ExceptionNotifier.ignore_if do |exception, passed_options|
      passed_options[:env].nil? && options[:ignore_if].call({}, exception)
    end
  end
end

.configured?Boolean

Whether Rake exception notifications have been configured.

Returns:

  • (Boolean)


11
12
13
# File 'lib/exception_notifier/rake/rake.rb', line 11

def self.configured?
  @configured
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.



42
43
44
45
46
47
48
49
50
51
# File 'lib/exception_notifier/rake/rake.rb', line 42

def self.maybe_deliver_notification(exception, data={})
  if configured?
    options = notifier_options
    if !data.empty?
      options = options.dup
      options[:data] = data.merge(options[:data] || {})
    end
    ExceptionNotifier.notify_exception(exception, options)
  end
end

.notifier_optionsObject



34
35
36
# File 'lib/exception_notifier/rake/rake.rb', line 34

def self.notifier_options
  @notifier_options
end

.reset_for_testObject



53
54
55
56
57
# File 'lib/exception_notifier/rake/rake.rb', line 53

def self.reset_for_test
  @notifier_options = {}
  @configured = false
  ExceptionNotifier.clear_ignore_conditions!
end