Class: LearnLab::FileSystem

Inherits:
Object
  • Object
show all
Defined in:
lib/learn_lab/file_system.rb

Overview

Wraps file system related commands.

Instance Method Summary collapse

Instance Method Details

#dir_entries(path) ⇒ Object

[View source]

59
60
61
# File 'lib/learn_lab/file_system.rb', line 59

def dir_entries(path)
  Dir.entries(path)
end

#dir_exist?(path) ⇒ Boolean

Returns:

  • (Boolean)
[View source]

55
56
57
# File 'lib/learn_lab/file_system.rb', line 55

def dir_exist?(path)
  Dir.exist?(path)
end

#directory?(path) ⇒ Boolean

Returns:

  • (Boolean)
[View source]

43
44
45
# File 'lib/learn_lab/file_system.rb', line 43

def directory?(path)
  File.directory?(path)
end

#dirname(path) ⇒ Object

[View source]

35
36
37
# File 'lib/learn_lab/file_system.rb', line 35

def dirname(path)
  File.dirname(path)
end

#file_exist?(path) ⇒ Boolean

Returns:

  • (Boolean)
[View source]

51
52
53
# File 'lib/learn_lab/file_system.rb', line 51

def file_exist?(path)
  File.exist?(path)
end

#homeObject

[View source]

23
24
25
# File 'lib/learn_lab/file_system.rb', line 23

def home
  Dir.home
end

#join(*args) ⇒ Object

[View source]

31
32
33
# File 'lib/learn_lab/file_system.rb', line 31

def join(*args)
  File.join(*args)
end

#mkdir(path) ⇒ Object

[View source]

39
40
41
# File 'lib/learn_lab/file_system.rb', line 39

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

#pwdObject

[View source]

27
28
29
# File 'lib/learn_lab/file_system.rb', line 27

def pwd
  FileUtils.pwd
end

#read_file(path) ⇒ Object

[View source]

7
8
9
# File 'lib/learn_lab/file_system.rb', line 7

def read_file(path)
  File.read(path)
end

#read_json_file(path) ⇒ Object

[View source]

18
19
20
21
# 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: {}) ⇒ Object

[View source]

11
12
13
14
15
16
# 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) ⇒ Object

[View source]

63
64
65
# File 'lib/learn_lab/file_system.rb', line 63

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

#write_yaml_file(path, data, **options) ⇒ Object

[View source]

47
48
49
# File 'lib/learn_lab/file_system.rb', line 47

def write_yaml_file(path, data, **options)
  File.write(path, data.to_yaml, **options)
end