backup 3.0.20 → 3.0.21

Sign up to get free protection for your applications and to get access to all the features.
Files changed (178) hide show
  1. data/Gemfile +1 -5
  2. data/Gemfile.lock +46 -50
  3. data/README.md +54 -27
  4. data/lib/backup.rb +16 -39
  5. data/lib/backup/archive.rb +42 -18
  6. data/lib/backup/cleaner.rb +110 -25
  7. data/lib/backup/cli/helpers.rb +17 -32
  8. data/lib/backup/cli/utility.rb +46 -107
  9. data/lib/backup/compressor/base.rb +14 -2
  10. data/lib/backup/compressor/bzip2.rb +10 -24
  11. data/lib/backup/compressor/gzip.rb +10 -24
  12. data/lib/backup/compressor/lzma.rb +10 -23
  13. data/lib/backup/compressor/pbzip2.rb +12 -32
  14. data/lib/backup/config.rb +171 -0
  15. data/lib/backup/configuration/compressor/base.rb +1 -2
  16. data/lib/backup/configuration/compressor/pbzip2.rb +4 -4
  17. data/lib/backup/configuration/database/base.rb +2 -1
  18. data/lib/backup/configuration/database/mongodb.rb +8 -0
  19. data/lib/backup/configuration/database/mysql.rb +4 -0
  20. data/lib/backup/configuration/database/postgresql.rb +4 -0
  21. data/lib/backup/configuration/database/redis.rb +4 -0
  22. data/lib/backup/configuration/database/riak.rb +5 -1
  23. data/lib/backup/configuration/encryptor/base.rb +1 -2
  24. data/lib/backup/configuration/encryptor/open_ssl.rb +1 -1
  25. data/lib/backup/configuration/helpers.rb +7 -2
  26. data/lib/backup/configuration/notifier/base.rb +4 -28
  27. data/lib/backup/configuration/storage/base.rb +1 -1
  28. data/lib/backup/configuration/storage/dropbox.rb +14 -4
  29. data/lib/backup/configuration/syncer/base.rb +10 -0
  30. data/lib/backup/configuration/syncer/rsync/base.rb +28 -0
  31. data/lib/backup/configuration/syncer/rsync/local.rb +11 -0
  32. data/lib/backup/configuration/syncer/rsync/pull.rb +11 -0
  33. data/lib/backup/configuration/syncer/rsync/push.rb +31 -0
  34. data/lib/backup/configuration/syncer/s3.rb +0 -4
  35. data/lib/backup/database/base.rb +25 -7
  36. data/lib/backup/database/mongodb.rb +112 -75
  37. data/lib/backup/database/mysql.rb +54 -29
  38. data/lib/backup/database/postgresql.rb +60 -42
  39. data/lib/backup/database/redis.rb +61 -39
  40. data/lib/backup/database/riak.rb +35 -11
  41. data/lib/backup/dependency.rb +4 -5
  42. data/lib/backup/encryptor/base.rb +13 -1
  43. data/lib/backup/encryptor/gpg.rb +39 -39
  44. data/lib/backup/encryptor/open_ssl.rb +28 -38
  45. data/lib/backup/logger.rb +20 -11
  46. data/lib/backup/model.rb +206 -163
  47. data/lib/backup/notifier/base.rb +27 -25
  48. data/lib/backup/notifier/campfire.rb +7 -13
  49. data/lib/backup/notifier/hipchat.rb +28 -28
  50. data/lib/backup/notifier/mail.rb +24 -26
  51. data/lib/backup/notifier/presently.rb +10 -18
  52. data/lib/backup/notifier/prowl.rb +9 -17
  53. data/lib/backup/notifier/twitter.rb +11 -18
  54. data/lib/backup/package.rb +47 -0
  55. data/lib/backup/packager.rb +81 -16
  56. data/lib/backup/splitter.rb +48 -35
  57. data/lib/backup/storage/base.rb +44 -172
  58. data/lib/backup/storage/cloudfiles.rb +31 -46
  59. data/lib/backup/storage/cycler.rb +117 -0
  60. data/lib/backup/storage/dropbox.rb +92 -76
  61. data/lib/backup/storage/ftp.rb +30 -40
  62. data/lib/backup/storage/local.rb +44 -45
  63. data/lib/backup/storage/ninefold.rb +55 -49
  64. data/lib/backup/storage/rsync.rb +49 -56
  65. data/lib/backup/storage/s3.rb +33 -44
  66. data/lib/backup/storage/scp.rb +21 -48
  67. data/lib/backup/storage/sftp.rb +26 -40
  68. data/lib/backup/syncer/base.rb +7 -0
  69. data/lib/backup/syncer/rsync/base.rb +78 -0
  70. data/lib/backup/syncer/rsync/local.rb +53 -0
  71. data/lib/backup/syncer/rsync/pull.rb +38 -0
  72. data/lib/backup/syncer/rsync/push.rb +113 -0
  73. data/lib/backup/syncer/s3.rb +42 -32
  74. data/lib/backup/version.rb +1 -1
  75. data/spec/archive_spec.rb +235 -69
  76. data/spec/cleaner_spec.rb +304 -0
  77. data/spec/cli/helpers_spec.rb +142 -1
  78. data/spec/cli/utility_spec.rb +338 -13
  79. data/spec/compressor/base_spec.rb +31 -0
  80. data/spec/compressor/bzip2_spec.rb +60 -35
  81. data/spec/compressor/gzip_spec.rb +60 -35
  82. data/spec/compressor/lzma_spec.rb +60 -35
  83. data/spec/compressor/pbzip2_spec.rb +98 -37
  84. data/spec/config_spec.rb +321 -0
  85. data/spec/configuration/base_spec.rb +4 -4
  86. data/spec/configuration/compressor/bzip2_spec.rb +1 -0
  87. data/spec/configuration/compressor/gzip_spec.rb +1 -0
  88. data/spec/configuration/compressor/lzma_spec.rb +1 -0
  89. data/spec/configuration/compressor/pbzip2_spec.rb +32 -0
  90. data/spec/configuration/database/base_spec.rb +2 -1
  91. data/spec/configuration/database/mongodb_spec.rb +26 -16
  92. data/spec/configuration/database/mysql_spec.rb +4 -0
  93. data/spec/configuration/database/postgresql_spec.rb +4 -0
  94. data/spec/configuration/database/redis_spec.rb +4 -0
  95. data/spec/configuration/database/riak_spec.rb +4 -0
  96. data/spec/configuration/encryptor/gpg_spec.rb +1 -0
  97. data/spec/configuration/encryptor/open_ssl_spec.rb +1 -0
  98. data/spec/configuration/notifier/base_spec.rb +32 -0
  99. data/spec/configuration/notifier/campfire_spec.rb +1 -0
  100. data/spec/configuration/notifier/hipchat_spec.rb +1 -0
  101. data/spec/configuration/notifier/mail_spec.rb +1 -0
  102. data/spec/configuration/notifier/presently_spec.rb +1 -0
  103. data/spec/configuration/notifier/prowl_spec.rb +1 -0
  104. data/spec/configuration/notifier/twitter_spec.rb +1 -0
  105. data/spec/configuration/storage/cloudfiles_spec.rb +1 -0
  106. data/spec/configuration/storage/dropbox_spec.rb +4 -3
  107. data/spec/configuration/storage/ftp_spec.rb +1 -0
  108. data/spec/configuration/storage/local_spec.rb +1 -0
  109. data/spec/configuration/storage/ninefold_spec.rb +1 -0
  110. data/spec/configuration/storage/rsync_spec.rb +3 -1
  111. data/spec/configuration/storage/s3_spec.rb +1 -0
  112. data/spec/configuration/storage/scp_spec.rb +1 -0
  113. data/spec/configuration/storage/sftp_spec.rb +1 -0
  114. data/spec/configuration/syncer/rsync/base_spec.rb +33 -0
  115. data/spec/configuration/syncer/rsync/local_spec.rb +10 -0
  116. data/spec/configuration/syncer/rsync/pull_spec.rb +10 -0
  117. data/spec/configuration/syncer/{rsync_spec.rb → rsync/push_spec.rb} +12 -15
  118. data/spec/configuration/syncer/s3_spec.rb +2 -3
  119. data/spec/database/base_spec.rb +35 -20
  120. data/spec/database/mongodb_spec.rb +298 -119
  121. data/spec/database/mysql_spec.rb +147 -72
  122. data/spec/database/postgresql_spec.rb +155 -100
  123. data/spec/database/redis_spec.rb +200 -97
  124. data/spec/database/riak_spec.rb +82 -24
  125. data/spec/dependency_spec.rb +49 -0
  126. data/spec/encryptor/base_spec.rb +30 -0
  127. data/spec/encryptor/gpg_spec.rb +105 -28
  128. data/spec/encryptor/open_ssl_spec.rb +85 -114
  129. data/spec/logger_spec.rb +74 -8
  130. data/spec/model_spec.rb +528 -220
  131. data/spec/notifier/base_spec.rb +89 -0
  132. data/spec/notifier/campfire_spec.rb +147 -119
  133. data/spec/notifier/hipchat_spec.rb +140 -145
  134. data/spec/notifier/mail_spec.rb +190 -248
  135. data/spec/notifier/presently_spec.rb +147 -282
  136. data/spec/notifier/prowl_spec.rb +79 -111
  137. data/spec/notifier/twitter_spec.rb +87 -106
  138. data/spec/package_spec.rb +61 -0
  139. data/spec/packager_spec.rb +154 -0
  140. data/spec/spec_helper.rb +36 -13
  141. data/spec/splitter_spec.rb +90 -41
  142. data/spec/storage/base_spec.rb +95 -239
  143. data/spec/storage/cloudfiles_spec.rb +185 -75
  144. data/spec/storage/cycler_spec.rb +239 -0
  145. data/spec/storage/dropbox_spec.rb +318 -87
  146. data/spec/storage/ftp_spec.rb +165 -152
  147. data/spec/storage/local_spec.rb +206 -54
  148. data/spec/storage/ninefold_spec.rb +264 -128
  149. data/spec/storage/rsync_spec.rb +244 -163
  150. data/spec/storage/s3_spec.rb +175 -64
  151. data/spec/storage/scp_spec.rb +156 -150
  152. data/spec/storage/sftp_spec.rb +153 -135
  153. data/spec/syncer/base_spec.rb +22 -0
  154. data/spec/syncer/rsync/base_spec.rb +118 -0
  155. data/spec/syncer/rsync/local_spec.rb +121 -0
  156. data/spec/syncer/rsync/pull_spec.rb +90 -0
  157. data/spec/syncer/rsync/push_spec.rb +327 -0
  158. data/spec/syncer/s3_spec.rb +180 -91
  159. data/templates/cli/utility/config +1 -1
  160. data/templates/cli/utility/database/mongodb +4 -0
  161. data/templates/cli/utility/database/mysql +3 -0
  162. data/templates/cli/utility/database/postgresql +3 -0
  163. data/templates/cli/utility/database/redis +3 -0
  164. data/templates/cli/utility/database/riak +3 -0
  165. data/templates/cli/utility/storage/dropbox +4 -1
  166. data/templates/cli/utility/syncer/rsync_local +12 -0
  167. data/templates/cli/utility/syncer/{rsync → rsync_pull} +2 -2
  168. data/templates/cli/utility/syncer/rsync_push +17 -0
  169. data/templates/storage/dropbox/authorization_url.erb +1 -1
  170. metadata +42 -17
  171. data/lib/backup/configuration/syncer/rsync.rb +0 -45
  172. data/lib/backup/finder.rb +0 -87
  173. data/lib/backup/storage/object.rb +0 -47
  174. data/lib/backup/syncer/rsync.rb +0 -152
  175. data/spec/backup_spec.rb +0 -11
  176. data/spec/finder_spec.rb +0 -91
  177. data/spec/storage/object_spec.rb +0 -74
  178. data/spec/syncer/rsync_spec.rb +0 -195
@@ -5,14 +5,6 @@ module Backup
5
5
  class Base
6
6
  include Backup::Configuration::Helpers
7
7
 
8
- ##
9
- # Container for the Model object
10
- attr_accessor :model
11
-
12
- ##
13
- # Contains the Backup::Template object
14
- attr_accessor :template
15
-
16
8
  ##
17
9
  # When set to true, the user will be notified by email
18
10
  # when a backup process ends without raising any exceptions
@@ -32,33 +24,35 @@ module Backup
32
24
  alias :notify_on_failure? :on_failure
33
25
 
34
26
  ##
35
- # Super method #initialize for all child classes
36
- def initialize(&block)
27
+ # Called with super(model) from subclasses
28
+ def initialize(model)
29
+ @model = model
37
30
  load_defaults!
38
31
 
39
- instance_eval(&block) if block_given?
40
-
41
- set_defaults!
32
+ @on_success = true if on_success.nil?
33
+ @on_warning = true if on_warning.nil?
34
+ @on_failure = true if on_failure.nil?
42
35
  end
43
36
 
44
37
  ##
45
38
  # Performs the notification
46
- # Takes an exception object that might've been created if an exception occurred.
47
- # If this is the case it'll invoke notify_failure!(exception), otherwise, if no
48
- # error was raised, it'll go ahead and notify_success!
49
- #
50
- # If'll only perform these if on_success is true or on_failure is true
51
- def perform!(model, exception = false)
52
- @model = model
53
- @template = Backup::Template.new({:model => model, :exception => exception})
39
+ # Takes a flag to indicate that a failure has occured.
40
+ # (this is only set from Model#perform! in the event of an error)
41
+ # If this is the case it will set the 'action' to :failure.
42
+ # Otherwise, it will set the 'action' to either :success or :warning,
43
+ # depending on whether or not any warnings were sent to the Logger.
44
+ # It will then invoke the notify! method with the 'action',
45
+ # but only if the proper on_success, on_warning or on_failure flag is true.
46
+ def perform!(failure = false)
47
+ @template = Backup::Template.new({:model => @model})
54
48
 
55
49
  action = false
56
- if exception.eql?(false)
50
+ if failure
51
+ action = :failure if notify_on_failure?
52
+ else
57
53
  if notify_on_success? || (notify_on_warning? && Logger.has_warnings?)
58
54
  action = Logger.has_warnings? ? :warning : :success
59
55
  end
60
- else
61
- action = :failure if notify_on_failure?
62
56
  end
63
57
 
64
58
  if action
@@ -67,11 +61,19 @@ module Backup
67
61
  end
68
62
  end
69
63
 
64
+ private
65
+
66
+ ##
67
+ # Return the notifier name, with Backup namespace removed
68
+ def notifier_name
69
+ self.class.to_s.sub('Backup::', '')
70
+ end
71
+
70
72
  ##
71
73
  # Logs a message to the console and log file to inform
72
74
  # the client that Backup is notifying about the process
73
75
  def log!
74
- Logger.message "#{ self.class } started notifying about the process."
76
+ Logger.message "#{ notifier_name } started notifying about the process."
75
77
  end
76
78
 
77
79
  end
@@ -30,15 +30,13 @@ module Backup
30
30
  # Campfire account's room id
31
31
  attr_accessor :room_id
32
32
 
33
- ##
34
- # Performs the notification
35
- # Extends from super class. Must call super(model, exception).
36
- # If any pre-configuration needs to be done, put it above the super(model, exception)
37
- def perform!(model, exception = false)
38
- super(model, exception)
33
+ def initialize(model, &block)
34
+ super(model)
35
+
36
+ instance_eval(&block) if block_given?
39
37
  end
40
38
 
41
- private
39
+ private
42
40
 
43
41
  ##
44
42
  # Notify the user of the backup operation results.
@@ -65,14 +63,10 @@ module Backup
65
63
  when :warning then 'Warning'
66
64
  when :failure then 'Failure'
67
65
  end
68
- message = "[Backup::%s] #{model.label} (#{model.trigger})" % name
66
+ message = "[Backup::%s] #{@model.label} (#{@model.trigger})" % name
69
67
  send_message(message)
70
68
  end
71
69
 
72
- ##
73
- # nothing to do
74
- def set_defaults!; end
75
-
76
70
  ##
77
71
  # Creates a new Campfire::Interface object and passes in the
78
72
  # campfire clients "room_id", "subdomain" and "api_token". Using this object
@@ -138,7 +132,7 @@ module Backup
138
132
  send_message(message)
139
133
  end
140
134
 
141
- private
135
+ private
142
136
 
143
137
  ##
144
138
  # Takes a "message" as argument, the "type" defaults to "Textmessage".
@@ -26,39 +26,38 @@ module Backup
26
26
  attr_accessor :rooms_notified
27
27
 
28
28
  ##
29
- # The background color of a success message. One of :yellow, :red, :green, :purple, or :random. (default: yellow)
29
+ # Notify users in the room
30
+ attr_accessor :notify_users
31
+
32
+ ##
33
+ # The background color of a success message.
34
+ # One of :yellow, :red, :green, :purple, or :random. (default: yellow)
30
35
  attr_accessor :success_color
31
36
 
32
37
  ##
33
- # The background color of a warning message. One of :yellow, :red, :green, :purple, or :random. (default: yellow)
38
+ # The background color of a warning message.
39
+ # One of :yellow, :red, :green, :purple, or :random. (default: yellow)
34
40
  attr_accessor :warning_color
35
41
 
36
42
  ##
37
- # The background color of an error message. One of :yellow, :red, :green, :purple, or :random. (default: yellow)
43
+ # The background color of an error message.
44
+ # One of :yellow, :red, :green, :purple, or :random. (default: yellow)
38
45
  attr_accessor :failure_color
39
46
 
40
- ##
41
- # Notify users in the room
42
- attr_accessor :notify_users
43
-
44
- ##
45
- # Performs the notification
46
- # Extends from super class. Must call super(model, exception).
47
- # If any pre-configuration needs to be done, put it above the super(model, exception)
48
- def perform!(model, exception = false)
49
- @rooms_notified = [rooms_notified].flatten
50
- super(model, exception)
51
- end
47
+ def initialize(model, &block)
48
+ super(model)
52
49
 
53
- private
50
+ @notify_users ||= false
51
+ @rooms_notified ||= []
52
+ @success_color ||= 'yellow'
53
+ @warning_color ||= 'yellow'
54
+ @failure_color ||= 'yellow'
54
55
 
55
- def send_message(msg, color, notify)
56
- client = HipChat::Client.new(token)
57
- rooms_notified.each do |room|
58
- client[room].send(from, msg, :color => color, :notify => notify)
59
- end
56
+ instance_eval(&block) if block_given?
60
57
  end
61
58
 
59
+ private
60
+
62
61
  ##
63
62
  # Notify the user of the backup operation results.
64
63
  # `status` indicates one of the following:
@@ -84,16 +83,17 @@ module Backup
84
83
  when :warning then ['Warning', warning_color]
85
84
  when :failure then ['Failure', failure_color]
86
85
  end
87
- message = "[Backup::%s] #{model.label} (#{model.trigger})" % name
88
- send_message(message, color, notify_users)
86
+ message = "[Backup::%s] #{@model.label} (#{@model.trigger})" % name
87
+ send_message(message, color)
89
88
  end
90
89
 
91
- def set_defaults!
92
- @success_color ||= 'yellow'
93
- @warning_color ||= 'yellow'
94
- @failure_color ||= 'yellow'
95
- @notify_users ||= false
90
+ def send_message(msg, color)
91
+ client = HipChat::Client.new(token)
92
+ [rooms_notified].flatten.each do |room|
93
+ client[room].send(from, msg, :color => color, :notify => notify_users)
94
+ end
96
95
  end
96
+
97
97
  end
98
98
  end
99
99
  end
@@ -8,10 +8,6 @@ module Backup
8
8
  module Notifier
9
9
  class Mail < Base
10
10
 
11
- ##
12
- # Container for the Mail object
13
- attr_reader :mail
14
-
15
11
  ##
16
12
  # Mail delivery method to be used by the Mail gem.
17
13
  # Supported methods:
@@ -94,15 +90,13 @@ module Backup
94
90
  # Example: '/tmp/test-mails'
95
91
  attr_accessor :mail_folder
96
92
 
97
- ##
98
- # Performs the notification
99
- # Extends from super class. Must call super(model, exception).
100
- # If any pre-configuration needs to be done, put it above the super(model, exception)
101
- def perform!(model, exception = false)
102
- super(model, exception)
93
+ def initialize(model, &block)
94
+ super(model)
95
+
96
+ instance_eval(&block) if block_given?
103
97
  end
104
98
 
105
- private
99
+ private
106
100
 
107
101
  ##
108
102
  # Notify the user of the backup operation results.
@@ -130,27 +124,31 @@ module Backup
130
124
  when :warning then [ 'Warning', true ]
131
125
  when :failure then [ 'Failure', true ]
132
126
  end
133
- mail.subject = "[Backup::%s] #{model.label} (#{model.trigger})" % name
134
- mail.body = template.result('notifier/mail/%s.erb' % status.to_s)
127
+
128
+ email = new_email
129
+ email.subject = "[Backup::%s] #{@model.label} (#{@model.trigger})" % name
130
+ email.body = @template.result('notifier/mail/%s.erb' % status.to_s)
131
+
135
132
  if send_log
136
- mail.convert_to_multipart
137
- mail.attachments["#{model.time}.#{model.trigger}.log"] = {
133
+ email.convert_to_multipart
134
+ email.attachments["#{@model.time}.#{@model.trigger}.log"] = {
138
135
  :mime_type => 'text/plain;',
139
136
  :content => Logger.messages.join("\n")
140
137
  }
141
138
  end
142
- mail.deliver!
139
+
140
+ email.deliver!
143
141
  end
144
142
 
145
143
  ##
146
144
  # Configures the Mail gem by setting the defaults.
147
- # Instantiates the @mail object with the @to and @from attributes
148
- def set_defaults!
149
- @delivery_method = %w{ smtp sendmail file test }.
145
+ # Creates and returns a new email, based on the @delivery_method used.
146
+ def new_email
147
+ method = %w{ smtp sendmail file test }.
150
148
  index(@delivery_method.to_s) ? @delivery_method.to_s : 'smtp'
151
149
 
152
150
  options =
153
- case @delivery_method
151
+ case method
154
152
  when 'smtp'
155
153
  { :address => @address,
156
154
  :port => @port,
@@ -166,19 +164,19 @@ module Backup
166
164
  opts.merge!(:arguments => @sendmail_args) if @sendmail_args
167
165
  opts
168
166
  when 'file'
169
- @mail_folder ||= "#{ENV['HOME']}/Backup/emails"
167
+ @mail_folder ||= File.join(Config.root_path, 'emails')
170
168
  { :location => File.expand_path(@mail_folder) }
171
169
  when 'test' then {}
172
170
  end
173
171
 
174
- method = @delivery_method.to_sym
175
172
  ::Mail.defaults do
176
- delivery_method method, options
173
+ delivery_method method.to_sym, options
177
174
  end
178
175
 
179
- @mail = ::Mail.new
180
- @mail.from = @from
181
- @mail.to = @to
176
+ email = ::Mail.new
177
+ email.to = @to
178
+ email.from = @from
179
+ email
182
180
  end
183
181
 
184
182
  end
@@ -6,10 +6,6 @@ module Backup
6
6
  module Notifier
7
7
  class Presently < Base
8
8
 
9
- ##
10
- # Container for the Presently Client object
11
- attr_accessor :presently_client
12
-
13
9
  ##
14
10
  # Presently subdomain
15
11
  attr_accessor :subdomain
@@ -22,16 +18,13 @@ module Backup
22
18
  # Group id
23
19
  attr_accessor :group_id
24
20
 
25
- ##
26
- # Performs the notification
27
- # Extends from super class. Must call super(model, exception).
28
- # If any pre-configuration needs to be done,
29
- # put it above the super(model, exception)
30
- def perform!(model, exception = false)
31
- super(model, exception)
21
+ def initialize(model, &block)
22
+ super(model)
23
+
24
+ instance_eval(&block) if block_given?
32
25
  end
33
26
 
34
- private
27
+ private
35
28
 
36
29
  ##
37
30
  # Notify the user of the backup operation results.
@@ -58,14 +51,13 @@ module Backup
58
51
  when :warning then 'Warning'
59
52
  when :failure then 'Failure'
60
53
  end
61
- message = "[Backup::%s] #{model.label} (#{model.trigger})" % name
62
- presently_client.update(message)
54
+ message = "[Backup::%s] #{@model.label} (#{@model.trigger})" % name
55
+ send_message(message)
63
56
  end
64
57
 
65
- ##
66
- # Create a default Presently::Client object
67
- def set_defaults!
68
- @presently_client = Client.new(subdomain, user_name, password, group_id)
58
+ def send_message(message)
59
+ client = Client.new(subdomain, user_name, password, group_id)
60
+ client.update(message)
69
61
  end
70
62
 
71
63
  class Client
@@ -8,10 +8,6 @@ module Backup
8
8
  module Notifier
9
9
  class Prowl < Base
10
10
 
11
- ##
12
- # Container for the Twitter Client object
13
- attr_accessor :prowl_client
14
-
15
11
  ##
16
12
  # Application name
17
13
  # Tell something like your server name. Example: "Server1 Backup"
@@ -22,15 +18,13 @@ module Backup
22
18
  # Create a Prowl account and request an API key on prowlapp.com.
23
19
  attr_accessor :api_key
24
20
 
25
- ##
26
- # Performs the notification
27
- # Extends from super class. Must call super(model, exception).
28
- # If any pre-configuration needs to be done, put it above the super(model, exception)
29
- def perform!(model, exception = false)
30
- super(model, exception)
21
+ def initialize(model, &block)
22
+ super(model)
23
+
24
+ instance_eval(&block) if block_given?
31
25
  end
32
26
 
33
- private
27
+ private
34
28
 
35
29
  ##
36
30
  # Notify the user of the backup operation results.
@@ -58,14 +52,12 @@ module Backup
58
52
  when :failure then 'Failure'
59
53
  end
60
54
  message = '[Backup::%s]' % name
61
- prowl_client.notify(message, "#{model.label} (#{model.trigger})")
55
+ send_message(message)
62
56
  end
63
57
 
64
- ##
65
- # Configures the Prowler object by passing in the @api_key and the
66
- # @application. Instantiates and sets the @prowl_client object
67
- def set_defaults!
68
- @prowl_client = Prowler.new(:application => application, :api_key => api_key)
58
+ def send_message(message)
59
+ client = Prowler.new(:application => application, :api_key => api_key)
60
+ client.notify(message, "#{@model.label} (#{@model.trigger})")
69
61
  end
70
62
 
71
63
  end
@@ -8,10 +8,6 @@ module Backup
8
8
  module Notifier
9
9
  class Twitter < Base
10
10
 
11
- ##
12
- # Container for the Twitter Client object
13
- attr_accessor :twitter_client
14
-
15
11
  ##
16
12
  # Twitter consumer key credentials
17
13
  attr_accessor :consumer_key, :consumer_secret
@@ -20,15 +16,13 @@ module Backup
20
16
  # OAuth credentials
21
17
  attr_accessor :oauth_token, :oauth_token_secret
22
18
 
23
- ##
24
- # Performs the notification
25
- # Extends from super class. Must call super(model, exception).
26
- # If any pre-configuration needs to be done, put it above the super(model, exception)
27
- def perform!(model, exception = false)
28
- super(model, exception)
19
+ def initialize(model, &block)
20
+ super(model)
21
+
22
+ instance_eval(&block) if block_given?
29
23
  end
30
24
 
31
- private
25
+ private
32
26
 
33
27
  ##
34
28
  # Notify the user of the backup operation results.
@@ -55,21 +49,20 @@ module Backup
55
49
  when :warning then 'Warning'
56
50
  when :failure then 'Failure'
57
51
  end
58
- message = "[Backup::%s] #{model.label} (#{model.trigger})" % name
59
- twitter_client.update(message)
52
+ message = "[Backup::%s] #{@model.label} (#{@model.trigger})" % name
53
+ send_message(message)
60
54
  end
61
55
 
62
- ##
63
- # Configures the Twitter object by passing in the @consumer_key, @consumer_secret
64
- # @oauth_token and @oauth_token_secret. Instantiates and sets the @twitter_client object
65
- def set_defaults!
56
+ def send_message(message)
66
57
  ::Twitter.configure do |config|
67
58
  config.consumer_key = @consumer_key
68
59
  config.consumer_secret = @consumer_secret
69
60
  config.oauth_token = @oauth_token
70
61
  config.oauth_token_secret = @oauth_token_secret
71
62
  end
72
- @twitter_client = ::Twitter::Client.new
63
+
64
+ client = ::Twitter::Client.new
65
+ client.update(message)
73
66
  end
74
67
 
75
68
  end