lib/bundleup/backup.rb in bundleup-2.0.0 vs lib/bundleup/backup.rb in bundleup-2.1.0
- old
+ new
@@ -1,26 +1,29 @@
module Bundleup
class Backup
- def self.restore_on_error(path)
- backup = new(path)
+ def self.restore_on_error(*paths)
+ backup = new(*paths)
begin
yield(backup)
rescue StandardError, Interrupt
backup.restore
raise
end
end
- def initialize(path)
- @path = path
- @original_contents = IO.read(path)
+ def initialize(*paths)
+ @original_contents = paths.each_with_object({}) do |path, hash|
+ hash[path] = IO.read(path)
+ end
end
def restore
- IO.write(path, original_contents)
+ original_contents.each do |path, contents|
+ IO.write(path, contents)
+ end
end
private
- attr_reader :path, :original_contents
+ attr_reader :original_contents
end
end