Class: Robocopy

Inherits:
Object
  • Object
show all
Includes:
Logging, RunCommand, YAMLConfig
Defined in:
lib/seabass/robocopy.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(env = @@env, executor = Executor.new) ⇒ Robocopy

Returns a new instance of Robocopy.



10
11
12
13
14
15
16
# File 'lib/seabass/robocopy.rb', line 10

def initialize(env = @@env, executor = Executor.new)
  @env = env
  @files = []
  @directories = []
  @executor = executor
  @mirror = false
end

Instance Attribute Details

#destinationObject

Returns the value of attribute destination.



8
9
10
# File 'lib/seabass/robocopy.rb', line 8

def destination
  @destination
end

#directoriesObject

Returns the value of attribute directories.



8
9
10
# File 'lib/seabass/robocopy.rb', line 8

def directories
  @directories
end

#filesObject

Returns the value of attribute files.



8
9
10
# File 'lib/seabass/robocopy.rb', line 8

def files
  @files
end

#mirrorObject

Returns the value of attribute mirror.



8
9
10
# File 'lib/seabass/robocopy.rb', line 8

def mirror
  @mirror
end

Instance Method Details

#executeObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/seabass/robocopy.rb', line 18

def execute()
  raise "No files or directories were specified" if @files.length == 0 and @directories.length == 0
  raise "Destination folder was not specified" if @destination.nil?

  copy = lambda { |type, collection|
    collection.each do |f|
      command = "#{@env.tools.robocopy} " + case type
        when 'file' then file_command(f, @destination)
        when 'directory' then directory_command(f, @destination)
        else raise "Unknown copy type"
      end
      command += " /MIR" if @mirror 

      Log.message("Copying #{f} #{destination}; #{command}", :info)
      @executor.run(command)
    end
  }

  copy.call('file', @files)
  copy.call('directory', @directories)
end