class LearnLab::FileSystem

Wraps file system related commands.

Public Instance Methods

dir_entries(path) click to toggle source
# File lib/learn_lab/file_system.rb, line 59
def dir_entries(path)
  Dir.entries(path)
end
dir_exist?(path) click to toggle source
# File lib/learn_lab/file_system.rb, line 55
def dir_exist?(path)
  Dir.exist?(path)
end
directory?(path) click to toggle source
# File lib/learn_lab/file_system.rb, line 43
def directory?(path)
  File.directory?(path)
end
dirname(path) click to toggle source
# File lib/learn_lab/file_system.rb, line 35
def dirname(path)
  File.dirname(path)
end
file_exist?(path) click to toggle source
# File lib/learn_lab/file_system.rb, line 51
def file_exist?(path)
  File.exist?(path)
end
home() click to toggle source
# File lib/learn_lab/file_system.rb, line 23
def home
  Dir.home
end
join(*args) click to toggle source
# File lib/learn_lab/file_system.rb, line 31
def join(*args)
  File.join(*args)
end
mkdir(path) click to toggle source
# File lib/learn_lab/file_system.rb, line 39
def mkdir(path)
  FileUtils.mkdir_p(path)
end
pwd() click to toggle source
# File lib/learn_lab/file_system.rb, line 27
def pwd
  FileUtils.pwd
end
read_file(path) click to toggle source
# File lib/learn_lab/file_system.rb, line 7
def read_file(path)
  File.read(path)
end
read_json_file(path) click to toggle source
# File lib/learn_lab/file_system.rb, line 18
def read_json_file(path)
  data = File.exist?(path) ? read_file(path) : '{}'
  JSON.parse(data, symbolize_names: true)
end
read_yaml_file(path, fallback: {}) click to toggle source
# File lib/learn_lab/file_system.rb, line 11
def read_yaml_file(path, fallback: {})
  data = YAML.load_file(path, fallback: fallback)
  data.transform_keys(&:to_sym)
rescue Errno::ENOENT, Psych::SyntaxError => e
  raise ConfigurationError.new(e)
end
rm(path) click to toggle source
# File lib/learn_lab/file_system.rb, line 63
def rm(path)
  FileUtils.rm(path)
end
write_yaml_file(path, data, **options) click to toggle source
# File lib/learn_lab/file_system.rb, line 47
def write_yaml_file(path, data, **options)
  File.write(path, data.to_yaml, **options)
end