class FileTransactions::DeleteFileCommand
This command supports deleting a file.
When this command has been executed, the file can be restored by calling undo
Examples¶ ↑
# Pass in the filename name to ::new cmd1 = DeleteFileCommand.new('some_existing_file')
Attributes
block[R]
name[R]
Public Class Methods
new(name)
click to toggle source
@param name [String] The name of the file to be deleted. May be just a name or an absolut or relative path
# File lib/file_transactions/delete_file_command.rb, line 20 def initialize(name) @name = name end
Private Instance Methods
before()
click to toggle source
# File lib/file_transactions/delete_file_command.rb, line 26 def before CreateFileCommand.execute(tmp_name) do FileUtils.copy name, tmp_name end end
execute!()
click to toggle source
# File lib/file_transactions/delete_file_command.rb, line 32 def execute! File.delete name end
tmp_name()
click to toggle source
# File lib/file_transactions/delete_file_command.rb, line 40 def tmp_name @tmp_name ||= File.join(Dir.mktmpdir, File.basename(name)) end
undo!()
click to toggle source
# File lib/file_transactions/delete_file_command.rb, line 36 def undo! FileUtils.copy tmp_name, name end