lib/backup/notifier/twitter.rb in backup-3.0.19 vs lib/backup/notifier/twitter.rb in backup-3.0.20

- old
+ new

@@ -11,63 +11,53 @@ ## # Container for the Twitter Client object attr_accessor :twitter_client ## - # Container for the Model object - attr_accessor :model - - ## # Twitter consumer key credentials attr_accessor :consumer_key, :consumer_secret ## # OAuth credentials attr_accessor :oauth_token, :oauth_token_secret ## - # Instantiates a new Backup::Notifier::Twitter object - def initialize(&block) - load_defaults! - - instance_eval(&block) if block_given? - - set_defaults! - end - - ## # Performs the notification - # Takes an exception object that might've been created if an exception occurred. - # If this is the case it'll invoke notify_failure!(exception), otherwise, if no - # error was raised, it'll go ahead and notify_success! - # - # If'll only perform these if on_success is true or on_failure is true + # Extends from super class. Must call super(model, exception). + # If any pre-configuration needs to be done, put it above the super(model, exception) def perform!(model, exception = false) - @model = model - - if notify_on_success? and exception.eql?(false) - log! - notify_success! - elsif notify_on_failure? and not exception.eql?(false) - log! - notify_failure!(exception) - end + super(model, exception) end private ## - # Sends a tweet informing the user that the backup operation - # proceeded without any errors - def notify_success! - twitter_client.update("[Backup::Succeeded] #{model.label} (#{ File.basename(Backup::Model.file) })") - end - - ## - # Sends a tweet informing the user that the backup operation - # raised an exception - def notify_failure!(exception) - twitter_client.update("[Backup::Failed] #{model.label} (#{ File.basename(Backup::Model.file) })") + # Notify the user of the backup operation results. + # `status` indicates one of the following: + # + # `:success` + # : The backup completed successfully. + # : Notification will be sent if `on_success` was set to `true` + # + # `:warning` + # : The backup completed successfully, but warnings were logged + # : Notification will be sent, including a copy of the current + # : backup log, if `on_warning` was set to `true` + # + # `:failure` + # : The backup operation failed. + # : Notification will be sent, including the Exception which caused + # : the failure, the Exception's backtrace, a copy of the current + # : backup log and other information if `on_failure` was set to `true` + # + def notify!(status) + name = case status + when :success then 'Success' + when :warning then 'Warning' + when :failure then 'Failure' + end + message = "[Backup::%s] #{model.label} (#{model.trigger})" % name + twitter_client.update(message) end ## # Configures the Twitter object by passing in the @consumer_key, @consumer_secret # @oauth_token and @oauth_token_secret. Instantiates and sets the @twitter_client object