Method: KubsCLI::FileHelper#copy

Defined in:
lib/kubs_cli/file_helper.rb

#copy(from:, to:) ⇒ Object

Copies a file or directory from one spot to another

Parameters:

  • from (Dir, File)

    Where to copy from

  • to (Dir, File)

    Where to copy to

Returns:

  • void



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/kubs_cli/file_helper.rb', line 13

def copy(from:, to:)
  return if file_does_not_exist(from)

  to_dir = File.dirname(File.expand_path(to))
  Rake.mkdir_p(to_dir) unless Dir.exist?(to_dir)
  return Rake.cp(from, to) unless File.directory?(from)

  Rake.mkdir_p(to)

  Dir["#{from}/*"].each do |dir|
    Rake.cp_r(dir, to) # next if File.directory?(dir)

    # Rake.cp(dir, to)
  end
end