Module: Swineherd::BaseFileSystem
- Included in:
- HadoopFileSystem, LocalFileSystem, S3FileSystem
- Defined in:
- lib/swineherd/filesystem/basefilesystem.rb
Overview
All methods a filesystem should have
Defined Under Namespace
Classes: BaseFile
Instance Method Summary collapse
-
#check_paths(paths) ⇒ Object
For running tasks idempotently.
-
#close(*args) ⇒ Object
Needs to close the filesystem by cleaning up any open connections, &c.
-
#cp(srcpath, dstpath) ⇒ Object
Recursively copies all files and directories under srcpath to dstpath.
-
#entries(dirpath) ⇒ Object
Give contained files/dirs.
-
#exists?(path) ⇒ Boolean
Returns true if the file or path exists and false otherwise.
-
#initialize(*args) ⇒ Object
Return a new instance of ‘this’ filesystem.
-
#mkpath(path) ⇒ Object
Make directory path if it does not (partly) exist.
-
#mv(srcpath, dstpath) ⇒ Object
Moves the source path to the destination path.
-
#open(path, mode = "r", &blk) ⇒ Object
Open a file in this filesystem.
-
#rm(path) ⇒ Object
Recursively delete the path and all paths below it.
-
#size(path) ⇒ Object
Recursively measure the size of path.
-
#type(path) ⇒ Object
Return file type (“directory” or “file” or “symlink”).
Instance Method Details
#check_paths(paths) ⇒ Object
For running tasks idempotently. Returns true if no paths exist, false if all paths exist, and raises an error otherwise.
76 77 78 79 80 81 |
# File 'lib/swineherd/filesystem/basefilesystem.rb', line 76 def check_paths paths exist_count = paths.inject(0){|cnt, path| cnt += 1 if exists?(path); cnt} raise "Indeterminate output state" if (exist_count > 0) && (exist_count < paths.size) return true if exist_count == 0 false end |
#close(*args) ⇒ Object
Needs to close the filesystem by cleaning up any open connections, &c.
86 87 |
# File 'lib/swineherd/filesystem/basefilesystem.rb', line 86 def close *args end |
#cp(srcpath, dstpath) ⇒ Object
Recursively copies all files and directories under srcpath to dstpath
51 52 |
# File 'lib/swineherd/filesystem/basefilesystem.rb', line 51 def cp srcpath, dstpath end |
#entries(dirpath) ⇒ Object
Give contained files/dirs
69 70 |
# File 'lib/swineherd/filesystem/basefilesystem.rb', line 69 def entries dirpath end |
#exists?(path) ⇒ Boolean
Returns true if the file or path exists and false otherwise.
39 40 |
# File 'lib/swineherd/filesystem/basefilesystem.rb', line 39 def exists? path end |
#initialize(*args) ⇒ Object
Return a new instance of ‘this’ filesystem. Classes that include this module are expected to know how to pull their particular set of arguments from *args and initialize themselves by opening any required connections, &c.
13 14 |
# File 'lib/swineherd/filesystem/basefilesystem.rb', line 13 def initialize *args end |
#mkpath(path) ⇒ Object
Make directory path if it does not (partly) exist
57 58 |
# File 'lib/swineherd/filesystem/basefilesystem.rb', line 57 def mkpath path end |
#mv(srcpath, dstpath) ⇒ Object
Moves the source path to the destination path
45 46 |
# File 'lib/swineherd/filesystem/basefilesystem.rb', line 45 def mv srcpath, dstpath end |
#open(path, mode = "r", &blk) ⇒ Object
Open a file in this filesystem. Should return a usable file handle for in the mode (read ‘r’ or ‘w’) given. File classes should, at minimum, have the methods defined in BaseFile
21 22 |
# File 'lib/swineherd/filesystem/basefilesystem.rb', line 21 def open path, mode="r", &blk end |
#rm(path) ⇒ Object
Recursively delete the path and all paths below it.
33 34 |
# File 'lib/swineherd/filesystem/basefilesystem.rb', line 33 def rm path end |
#size(path) ⇒ Object
Recursively measure the size of path. Results in bytes.
27 28 |
# File 'lib/swineherd/filesystem/basefilesystem.rb', line 27 def size path end |
#type(path) ⇒ Object
Return file type (“directory” or “file” or “symlink”)
63 64 |
# File 'lib/swineherd/filesystem/basefilesystem.rb', line 63 def type path end |