lib/backup/notifier/twitter.rb in backup-3.5.1 vs lib/backup/notifier/twitter.rb in backup-3.6.0

- old
+ new

@@ -12,45 +12,43 @@ ## # OAuth credentials attr_accessor :oauth_token, :oauth_token_secret def initialize(model, &block) - super(model) - + super instance_eval(&block) if block_given? end private ## # 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` + # : Notification will be sent if `on_success` is `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` + # : The backup completed successfully, but warnings were logged. + # : Notification will be sent if `on_warning` or `on_success` is `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` + # : Notification will be sent if `on_warning` or `on_success` is `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}) (@ #{@model.time})" % name + tag = case status + when :success then '[Backup::Success]' + when :warning then '[Backup::Warning]' + when :failure then '[Backup::Failure]' + end + message = "#{ tag } #{ model.label } (#{ model.trigger }) (@ #{ model.time })" send_message(message) end + # Twitter::Client will raise an error if unsuccessful. def send_message(message) ::Twitter.configure do |config| config.consumer_key = @consumer_key config.consumer_secret = @consumer_secret config.oauth_token = @oauth_token