class KubsCLI::FileHelper

Used for copying files within kubs_cli

Public Instance Methods

copy(from:, to:) click to toggle source

Copies a file or directory from one spot to another @param from [Dir, File] Where to copy from @param to [Dir, File] Where to copy to @return void

# 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
load_yaml(file) click to toggle source

Loads a YAML file @param file [File] Yaml formatted file @return [Hash] Returns a hash from a yaml document

# File lib/kubs_cli/file_helper.rb, line 39
def load_yaml(file)
  YAML.load_file(file)
rescue StandardError => e
  KubsCLI.add_error(e: e, msg: "Unable to parse your YAML file - #{file}")
end
mkdirs(*dirs) click to toggle source

Creates dirs using Rake.mkdir_p if it does not exist @param dirs [Array<String>] The names of the dirs to create @return void

# File lib/kubs_cli/file_helper.rb, line 32
def mkdirs(*dirs)
  dirs.flatten.each { |dir| Rake.mkdir_p(dir) unless Dir.exist?(dir) }
end