Module: Filander::CopyFile

Includes:
Base
Included in:
Filander
Defined in:
lib/filander/actions/copy_file.rb

Instance Method Summary collapse

Methods included from Base

#create_directory_for, #entries, #join_destination, #join_source, #report, #with_report

Instance Method Details

#copy_file(source, destination = source) ⇒ Object



5
6
7
8
9
10
11
12
13
14
# File 'lib/filander/actions/copy_file.rb', line 5

def copy_file(source, destination = source)
  create_directory_for destination
  filename = join_source(source)
  raise "Source file `#{filename}' does not exist" if !File.exists?(filename) && Filander.behavior != :pretend

  content = File.read(filename) rescue nil
  with_report destination, content do
    FileUtils.cp filename, join_destination(destination)
  end
end