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

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.



70
71
72
73
74
75
# File 'lib/swineherd/filesystem/basefilesystem.rb', line 70

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.



80
81
# File 'lib/swineherd/filesystem/basefilesystem.rb', line 80

def close *args
end

#cp(srcpath, dstpath) ⇒ Object

Recursively copies all files and directories under srcpath to dstpath



45
46
# File 'lib/swineherd/filesystem/basefilesystem.rb', line 45

def cp srcpath, dstpath
end

#entries(dirpath) ⇒ Object

Give contained files/dirs



63
64
# File 'lib/swineherd/filesystem/basefilesystem.rb', line 63

def entries dirpath
end

#exists?(path) ⇒ Boolean

Returns true if the file or path exists and false otherwise.

Returns:

  • (Boolean)


33
34
# File 'lib/swineherd/filesystem/basefilesystem.rb', line 33

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



51
52
# File 'lib/swineherd/filesystem/basefilesystem.rb', line 51

def mkpath path
end

#mv(srcpath, dstpath) ⇒ Object

Moves the source path to the destination path



39
40
# File 'lib/swineherd/filesystem/basefilesystem.rb', line 39

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.



27
28
# File 'lib/swineherd/filesystem/basefilesystem.rb', line 27

def rm path
end

#type(path) ⇒ Object

Return file type (“directory” or “file” or “symlink”)



57
58
# File 'lib/swineherd/filesystem/basefilesystem.rb', line 57

def type path
end