Class: FileTransactions::MoveFileCommand

Inherits:
BaseCommand show all
Defined in:
lib/file_transactions/move_file_command.rb

Overview

This command supports moveing (renaming) a file. It will also create parent directories if the given path contains directories that doesn’t exist.

When this command has been executed, the file can be moved back to the original location again by calling #undo. Any directories created during #execute will be deleted.

Examples

cmd1 = MoveFileCommand.new('some_existing_file', 'some_new_dir/a_new_name')

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from BaseCommand

execute, #execute, #executed?, #failed?, #register, #undo

Constructor Details

#initialize(from:, to:) ⇒ MoveFileCommand

Returns a new instance of MoveFileCommand.

Parameters:

  • from (String)

    The name of the source file to be renamed. May be just a name or an absolut or relative path

  • to (String)

    The target name of the file. May be just a name or an absolut or relative path



19
20
21
22
# File 'lib/file_transactions/move_file_command.rb', line 19

def initialize(from:, to:)
  @from = from
  @to = to
end

Instance Attribute Details

#fromObject (readonly)

Returns the value of attribute from.



15
16
17
# File 'lib/file_transactions/move_file_command.rb', line 15

def from
  @from
end

#toObject (readonly)

Returns the value of attribute to.



15
16
17
# File 'lib/file_transactions/move_file_command.rb', line 15

def to
  @to
end