Class: Tumugi::Plugin::LocalFileSystem
- Inherits:
-
Object
- Object
- Tumugi::Plugin::LocalFileSystem
- Defined in:
- lib/tumugi/plugin/local_file_system.rb
Instance Method Summary collapse
- #directory?(path) ⇒ Boolean
- #entries(path) ⇒ Object
- #exist?(path) ⇒ Boolean
- #mkdir(path, parents: true, raise_if_exist: false) ⇒ Object
- #move(src, dest, raise_if_exist: false) ⇒ Object
- #remove(path, recursive: true) ⇒ Object
Instance Method Details
#directory?(path) ⇒ Boolean
43 44 45 |
# File 'lib/tumugi/plugin/local_file_system.rb', line 43 def directory?(path) File.directory?(path) end |
#entries(path) ⇒ Object
47 48 49 50 51 52 53 |
# File 'lib/tumugi/plugin/local_file_system.rb', line 47 def entries(path) if directory?(path) Dir.glob(File.join(path, '*')) else raise NotADirectoryError end end |
#exist?(path) ⇒ Boolean
8 9 10 |
# File 'lib/tumugi/plugin/local_file_system.rb', line 8 def exist?(path) File.exist?(path) end |
#mkdir(path, parents: true, raise_if_exist: false) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/tumugi/plugin/local_file_system.rb', line 20 def mkdir(path, parents: true, raise_if_exist: false) if File.exist?(path) if raise_if_exist raise FileAlreadyExistError.new("Path #{path} is already exist") elsif !directory?(path) raise NotADirectoryError.new("Path #{path} is not a directory") else return end end if parents FileUtils.mkdir_p(path) else parent_path = File.("..", path) if File.exist?(parent_path) FileUtils.mkdir(path) else raise MissingParentDirectoryError.new("Parent path #{parent_path} is not exist") end end end |
#move(src, dest, raise_if_exist: false) ⇒ Object
55 56 57 58 59 60 |
# File 'lib/tumugi/plugin/local_file_system.rb', line 55 def move(src, dest, raise_if_exist: false) if File.exist?(dest) && raise_if_exist raise FileAlreadyExistError end FileUtils.mv(src, dest, force: true) end |
#remove(path, recursive: true) ⇒ Object
12 13 14 15 16 17 18 |
# File 'lib/tumugi/plugin/local_file_system.rb', line 12 def remove(path, recursive: true) if recursive && directory?(path) FileUtils.rm_r(path) else FileUtils.remove_file(path) end end |