Class: KubsCLI::FileHelper
- Inherits:
-
Object
- Object
- KubsCLI::FileHelper
- Defined in:
- lib/kubs_cli/file_helper.rb
Overview
Used for copying files within kubs_cli
Instance Method Summary collapse
-
#copy(from:, to:) ⇒ Object
Copies a file or directory from one spot to another.
-
#load_yaml(file) ⇒ Hash
Loads a YAML file.
-
#mkdirs(*dirs) ⇒ Object
Creates dirs using Rake.mkdir_p if it does not exist.
Instance Method Details
#copy(from:, to:) ⇒ Object
Copies a file or directory from one spot to another
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.(to)) FileUtils.mkdir_p(to_dir) unless Dir.exist?(to_dir) return FileUtils.cp(from, to) unless File.directory?(from) FileUtils.mkdir_p(to) Dir["#{from}/*"].each do |dir| FileUtils.cp_r(dir, to) # next if File.directory?(dir) # FileUtils.cp(dir, to) end end |
#load_yaml(file) ⇒ Hash
Loads a YAML file
39 40 41 42 43 |
# 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) ⇒ Object
Creates dirs using Rake.mkdir_p if it does not exist
32 33 34 |
# File 'lib/kubs_cli/file_helper.rb', line 32 def mkdirs(*dirs) dirs.flatten.each { |dir| FileUtils.mkdir_p(dir) unless Dir.exist?(dir) } end |