Class: Swineherd::LocalFileSystem
- Inherits:
-
Object
- Object
- Swineherd::LocalFileSystem
- Defined in:
- lib/swineherd-fs/localfilesystem.rb
Instance Method Summary collapse
- #cp(srcpath, dstpath) ⇒ Object
- #cp_r(srcpath, dstpath) ⇒ Object
- #directory?(path) ⇒ Boolean
- #exists?(path) ⇒ Boolean
-
#initialize(*args) ⇒ LocalFileSystem
constructor
include Swineherd::BaseFileSystem.
-
#ls(path) ⇒ Object
List directory contents,similar to unix ‘ls` Dir to return files in immediate directory of @path@.
-
#ls_r(path) ⇒ Object
Recursively list directory contents Dir[@path@/*/],similar to unix ‘ls -R`.
- #mkdir_p(path) ⇒ Object
- #mv(srcpath, dstpath) ⇒ Object
- #open(path, mode = "r", &blk) ⇒ Object
- #rm(path) ⇒ Object
-
#rm_r(path) ⇒ Object
A leaky abstraction, should be called rm_rf if it calls rm_rf.
-
#size(path) ⇒ Object
Globs for files at @path@, append ‘*/’ to glob recursively.
Constructor Details
#initialize(*args) ⇒ LocalFileSystem
include Swineherd::BaseFileSystem
5 6 |
# File 'lib/swineherd-fs/localfilesystem.rb', line 5 def initialize *args end |
Instance Method Details
#cp(srcpath, dstpath) ⇒ Object
38 39 40 |
# File 'lib/swineherd-fs/localfilesystem.rb', line 38 def cp srcpath, dstpath FileUtils.cp(srcpath,dstpath) end |
#cp_r(srcpath, dstpath) ⇒ Object
42 43 44 |
# File 'lib/swineherd-fs/localfilesystem.rb', line 42 def cp_r srcpath, dstpath FileUtils.cp_r(srcpath,dstpath) end |
#directory?(path) ⇒ Boolean
30 31 32 |
# File 'lib/swineherd-fs/localfilesystem.rb', line 30 def directory? path File.directory? path end |
#exists?(path) ⇒ Boolean
26 27 28 |
# File 'lib/swineherd-fs/localfilesystem.rb', line 26 def exists? path File.exists?(path) end |
#ls(path) ⇒ Object
List directory contents,similar to unix ‘ls` Dir to return files in immediate directory of @path@
52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/swineherd-fs/localfilesystem.rb', line 52 def ls path if exists?(path) if !directory?(path) [path] else path += '/' unless path =~ /\/$/ Dir[path+'*'] end else raise Errno::ENOENT, "No such file or directory - #{path}" end end |
#ls_r(path) ⇒ Object
Recursively list directory contents Dir[@path@/*/],similar to unix ‘ls -R`
67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/swineherd-fs/localfilesystem.rb', line 67 def ls_r path if exists?(path) if !directory?(path) [path] else path += '/' unless path =~ /\/$/ Dir[path+'**/*'] end else raise Errno::ENOENT, "No such file or directory - #{path}" end end |
#mkdir_p(path) ⇒ Object
46 47 48 |
# File 'lib/swineherd-fs/localfilesystem.rb', line 46 def mkdir_p path FileUtils.mkdir_p path end |
#mv(srcpath, dstpath) ⇒ Object
34 35 36 |
# File 'lib/swineherd-fs/localfilesystem.rb', line 34 def mv srcpath, dstpath FileUtils.mv(srcpath,dstpath) end |
#open(path, mode = "r", &blk) ⇒ Object
8 9 10 |
# File 'lib/swineherd-fs/localfilesystem.rb', line 8 def open path, mode="r", &blk File.open(path,mode,&blk) end |
#rm(path) ⇒ Object
22 23 24 |
# File 'lib/swineherd-fs/localfilesystem.rb', line 22 def rm path FileUtils.rm path end |
#rm_r(path) ⇒ Object
A leaky abstraction, should be called rm_rf if it calls rm_rf
18 19 20 |
# File 'lib/swineherd-fs/localfilesystem.rb', line 18 def rm_r path FileUtils.rm_rf path end |
#size(path) ⇒ Object
Globs for files at @path@, append ‘*/’ to glob recursively
13 14 15 |
# File 'lib/swineherd-fs/localfilesystem.rb', line 13 def size path Dir[path].inject(0){|s,f|s+=File.size(f)} end |