class Bundleup::Backup

Attributes

original_contents[R]

Public Class Methods

new(*paths) click to toggle source
# File lib/bundleup/backup.rb, line 13
def initialize(*paths)
  @original_contents = paths.each_with_object({}) do |path, hash|
    hash[path] = File.read(path)
  end
end
restore_on_error(*paths) { |backup| ... } click to toggle source
# File lib/bundleup/backup.rb, line 3
def self.restore_on_error(*paths)
  backup = new(*paths)
  begin
    yield(backup)
  rescue StandardError, Interrupt
    backup.restore
    raise
  end
end

Public Instance Methods

restore() click to toggle source
# File lib/bundleup/backup.rb, line 19
def restore
  original_contents.each do |path, contents|
    File.write(path, contents)
  end
end