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
42 43 44 |
# File 'lib/tumugi/plugin/local_file_system.rb', line 42 def directory?(path) File.directory?(path) end |
#entries(path) ⇒ Object
46 47 48 49 50 51 52 |
# File 'lib/tumugi/plugin/local_file_system.rb', line 46 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 |
# 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 elsif !directory?(path) raise NotADirectoryError else return end end if parents FileUtils.mkdir_p(path) else if File.exist?(File.("..", path)) FileUtils.mkdir(path) else raise MissingParentDirectoryError end end end |
#move(src, dest, raise_if_exist: false) ⇒ Object
54 55 56 57 58 59 |
# File 'lib/tumugi/plugin/local_file_system.rb', line 54 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 |