Class: Backup::Notifier::Base

Inherits:
Object
  • Object
show all
Includes:
Configuration::Helpers
Defined in:
lib/backup/notifier/base.rb

Direct Known Subclasses

Campfire, Hipchat, Mail, Prowl, Pushover, Twitter

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Configuration::Helpers

included

Constructor Details

#initialize(model) ⇒ Base

Called with super(model) from subclasses



28
29
30
31
32
33
34
35
# File 'lib/backup/notifier/base.rb', line 28

def initialize(model)
  @model = model
  load_defaults!

  @on_success = true if on_success.nil?
  @on_warning = true if on_warning.nil?
  @on_failure = true if on_failure.nil?
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Backup::Configuration::Helpers

Instance Attribute Details

#on_failureObject Also known as: notify_on_failure?

When set to true, the user will be notified by email when a backup process raises an exception before finishing



23
24
25
# File 'lib/backup/notifier/base.rb', line 23

def on_failure
  @on_failure
end

#on_successObject Also known as: notify_on_success?

When set to true, the user will be notified by email when a backup process ends without raising any exceptions



11
12
13
# File 'lib/backup/notifier/base.rb', line 11

def on_success
  @on_success
end

#on_warningObject Also known as: notify_on_warning?

When set to true, the user will be notified by email when a backup process is successful, but has warnings



17
18
19
# File 'lib/backup/notifier/base.rb', line 17

def on_warning
  @on_warning
end

Instance Method Details

#perform!(failure = false) ⇒ Object

Performs the notification Takes a flag to indicate that a failure has occured. (this is only set from Model#perform! in the event of an error) If this is the case it will set the ‘action’ to :failure. Otherwise, it will set the ‘action’ to either :success or :warning, depending on whether or not any warnings were sent to the Logger. It will then invoke the notify! method with the ‘action’, but only if the proper on_success, on_warning or on_failure flag is true.



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/backup/notifier/base.rb', line 46

def perform!(failure = false)
  @template  = Backup::Template.new({:model => @model})

  action = false
  if failure
    action = :failure if notify_on_failure?
  else
    if notify_on_success? || (notify_on_warning? && Logger.has_warnings?)
      action = Logger.has_warnings? ? :warning : :success
    end
  end

  if action
    log!
    notify!(action)
  end
end