Class: LearnLab::FileSystem
- Inherits:
-
Object
- Object
- LearnLab::FileSystem
- Defined in:
- lib/learn_lab/file_system.rb
Overview
Wraps file system related commands.
Instance Method Summary collapse
- #dir_entries(path) ⇒ Object
- #dir_exist?(path) ⇒ Boolean
- #directory?(path) ⇒ Boolean
- #dirname(path) ⇒ Object
- #file_exist?(path) ⇒ Boolean
- #home ⇒ Object
- #join(*args) ⇒ Object
- #mkdir(path) ⇒ Object
- #pwd ⇒ Object
- #read_file(path) ⇒ Object
- #read_json_file(path) ⇒ Object
- #read_yaml_file(path, fallback: {}) ⇒ Object
- #rm(path) ⇒ Object
- #write_yaml_file(path, data, **options) ⇒ Object
Instance Method Details
permalink #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 |
permalink #dir_exist?(path) ⇒ Boolean
55 56 57 |
# File 'lib/learn_lab/file_system.rb', line 55 def dir_exist?(path) Dir.exist?(path) end |
permalink #directory?(path) ⇒ Boolean
43 44 45 |
# File 'lib/learn_lab/file_system.rb', line 43 def directory?(path) File.directory?(path) end |
permalink #dirname(path) ⇒ Object
[View source]
35 36 37 |
# File 'lib/learn_lab/file_system.rb', line 35 def dirname(path) File.dirname(path) end |
permalink #file_exist?(path) ⇒ Boolean
51 52 53 |
# File 'lib/learn_lab/file_system.rb', line 51 def file_exist?(path) File.exist?(path) end |
permalink #home ⇒ Object
[View source]
23 24 25 |
# File 'lib/learn_lab/file_system.rb', line 23 def home Dir.home end |
permalink #join(*args) ⇒ Object
[View source]
31 32 33 |
# File 'lib/learn_lab/file_system.rb', line 31 def join(*args) File.join(*args) end |
permalink #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 |
permalink #pwd ⇒ Object
[View source]
27 28 29 |
# File 'lib/learn_lab/file_system.rb', line 27 def pwd FileUtils.pwd end |
permalink #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 |
permalink #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 |
permalink #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 |
permalink #rm(path) ⇒ Object
[View source]
63 64 65 |
# File 'lib/learn_lab/file_system.rb', line 63 def rm(path) FileUtils.rm(path) end |
permalink #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, **) File.write(path, data.to_yaml, **) end |