Class: MoveCommand

Inherits:
Command show all
Defined in:
lib/commands.rb

Overview

Move files ###################################

Instance Attribute Summary

Attributes inherited from Command

#path

Instance Method Summary collapse

Methods inherited from Command

#<=>, #run, #transform

Constructor Details

#initialize(*args) ⇒ MoveCommand

Returns a new instance of MoveCommand.



38
39
40
# File 'lib/commands.rb', line 38

def initialize *args
  (@filename, @directory, @path)=args
end

Instance Method Details

#directoryObject



43
# File 'lib/commands.rb', line 43

def directory ; transform @directory ; end

#dry_runObject



45
46
47
48
49
50
51
52
53
54
# File 'lib/commands.rb', line 45

def dry_run
  case $OPTS[:on_collision]
  when 'overwrite'
    "mv #{filename} #{directory}"
  when 'rename'
    "mv #{filename} #{File.join(directory,unique_name)}"
  else # 'ignore' also
    # emit nothing
  end
end

#filenameObject



42
# File 'lib/commands.rb', line 42

def filename ; transform @filename ; end

#priorityObject



36
# File 'lib/commands.rb', line 36

def priority ; 2 ; end

#real_runObject



56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/commands.rb', line 56

def real_run
  case $OPTS[:on_collision]
  when 'overwrite'
    mv
  when 'rename'
    if collision?
      FileUtils.mv filename, File.join(directory,unique_name)
    else
      mv
    end
  else # captures the 'ignore' option too
    # do nothing
  end
end