Class: Bozo::Publishers::FileCopy

Inherits:
Object
  • Object
show all
Defined in:
lib/bozo/publishers/file_copy.rb

Overview

Publisher that copies files from one location to another.

Instance Method Summary collapse

Constructor Details

#initializeFileCopy

Creates a new instance.



9
10
11
# File 'lib/bozo/publishers/file_copy.rb', line 9

def initialize
  @directories = []
end

Instance Method Details

#destination(destination) ⇒ Object

Set the destination directory of the file copy.

Must be an absolute path.



31
32
33
# File 'lib/bozo/publishers/file_copy.rb', line 31

def destination(destination)
  @destination = destination
end

#directory(*args) ⇒ Object

Adds a source directory of files copy.

Must be relative to the project root. All files within the directory and its subdirectories will be copied to the destination directory, maintaining the file structure.



21
22
23
# File 'lib/bozo/publishers/file_copy.rb', line 21

def directory(*args)
  @directories << args
end

#executeObject



35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/bozo/publishers/file_copy.rb', line 35

def execute
  if @directories.empty? or @destination.nil?
    raise Bozo::ConfigurationError.new 'You must specify at least one source file or directory AND a destination directory'
  end

  ensure_no_clashing_files

  copy_pairs do |source, target|
    FileUtils.mkdir_p File.dirname(target)
    log_debug "Publishing \"#{File.basename(source)}\" to \"#{target}\""
    FileUtils.cp source, target
  end
end