Class: VimPK::Commands::Move
- Inherits:
-
Object
- Object
- VimPK::Commands::Move
- Defined in:
- lib/vimpk/commands/move.rb
Instance Attribute Summary collapse
-
#dest ⇒ Object
readonly
Returns the value of attribute dest.
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(name, options) ⇒ Move
constructor
A new instance of Move.
Constructor Details
#initialize(name, options) ⇒ Move
Returns a new instance of Move.
8 9 10 11 12 13 14 |
# File 'lib/vimpk/commands/move.rb', line 8 def initialize(name, ) raise ArgumentError, "New pack or type is required" unless .pack || .type @name = name || raise(ArgumentError, "Package name is required") @path = .path @pack = .pack @type = .type end |
Instance Attribute Details
#dest ⇒ Object (readonly)
Returns the value of attribute dest.
6 7 8 |
# File 'lib/vimpk/commands/move.rb', line 6 def dest @dest end |
Instance Method Details
#call ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/vimpk/commands/move.rb', line 16 def call glob = Dir.glob(File.join(@path, "*", "{start,opt}", @name)) if glob.empty? raise PackageNotFoundError, "Package #{@name} not found in #{@path}." elsif glob.size > 1 raise MultiplePackagesFoundError, "Multiple packages #{@name} found in #{glob.join(" and ")}." else source = glob.first current_type = File.basename(File.dirname(source)) current_pack = File.basename(File.dirname(File.dirname(source))) @dest = File.join(@path, @pack || current_pack, @type || current_type, @name) if File.exist?(dest) raise ArgumentError, "Package #{@name} already exists in #{dest}." else FileUtils.mkdir_p(File.dirname(dest)) end FileUtils.mv(source, dest) end end |