Module: Backup::CLI

Instance Method Summary collapse

Instance Method Details

#mkdir(path) ⇒ Object

Wrapper method for FileUtils.mkdir_p to create directories through a ruby method. This helps with test coverage and improves readability



18
19
20
# File 'lib/backup/cli.rb', line 18

def mkdir(path)
  FileUtils.mkdir_p(path)
end

#rm(path) ⇒ Object

Wrapper for the FileUtils.rm_rf to remove files and folders through a ruby method. This helps with test coverage and improves readability



26
27
28
# File 'lib/backup/cli.rb', line 26

def rm(path)
  FileUtils.rm_rf(path)
end

#run(command) ⇒ Object

Wrapper method for %x[] to run CL commands through a ruby method. This helps with test coverage and improves readability



10
11
12
# File 'lib/backup/cli.rb', line 10

def run(command)
  %x[#{command}]
end

#utility(name) ⇒ Object

Tries to find the full path of the specified utility. If the full path is found, it’ll return that. Otherwise it’ll just return the name of the utility. If the ‘utility_path’ is defined, it’ll check to see if it isn’t an empty string, and if it isn’t, it’ll go ahead and always use that path rather than auto-detecting it



36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/backup/cli.rb', line 36

def utility(name)
  if respond_to?(:utility_path)
    if utility_path.is_a?(String) and not utility_path.empty?
      return utility_path
    end
  end

  if path = %x[which #{name}].chomp and not path.empty?
    return path
  end
  name
end