lib/rdiff_simple/rdiff_backup.rb in rdiff-simple-0.1.0 vs lib/rdiff_simple/rdiff_backup.rb in rdiff-simple-0.1.1
- old
+ new
@@ -1,20 +1,35 @@
-
module RdiffSimple
class RdiffBackup
- def initialize(logger = Logger.new(STDOUT), open3 = Open3)
- @logger = logger
- @open3 = open3
+ attr_accessor :logger, :open3
+
+ def initialize
+ yield self if block_given?
+
+ @open3 ||= Open3
+ @logger ||= Logger.new(STDOUT)
end
- def execute(*args)
- command_arguments = OptionsParser.parse(*args)
+ def backup(source, destination, *args)
+ command_args = OptionsParser.parse *args
+ execute "#{command_args} #{source} #{destination}"
+ end
- out, err, result = @open3.capture3("rdiff-backup #{command_arguments}".strip)
+ def verify(destination)
+ verify_at_time destination, "now"
+ end
- @logger.info(out) if out.length > 0
- @logger.error(err) if err.length > 0
+ def verify_at_time(destination, time)
+ execute "--verify-at-time #{time} #{destination}"
+ end
- return result.exitstatus
+ private
+ def execute(command)
+ output, error, result = open3.capture3 "rdiff-backup #{command}"
+
+ logger.info output unless output.empty?
+ logger.error error unless error.empty?
+
+ result.exitstatus
end
end
end