Method: Template::Spec#transfer_file

Defined in:
lib/template/spec.rb

#transfer_file(source_file, target_file, overwrite) ⇒ Object



239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
# File 'lib/template/spec.rb', line 239

def transfer_file(source_file, target_file, overwrite)
  FileUtils.mkdir_p File.dirname(target_file)

  if File.directory? source_file
    FileUtils.mkdir_p target_file
  elsif !File.exists?(target_file) || overwrite
    if File.binary? source_file
      FileUtils.cp(source_file, target_file)
    else
      begin
        IO.write target_file, replace_tokens(File.read(source_file))
      rescue
        FileUtils.cp(source_file, target_file)
      end
    end
  else
    raise "#{target_file} already exists, not overwriting. Use -f to force overwriting."
  end

  target_file
end