Class: DRbFileClientReadWrite
- Inherits:
-
DRbFileClientReader
- Object
- DRbFileClientReader
- DRbFileClientReadWrite
- Defined in:
- lib/drb_fileclient-readwrite.rb
Instance Method Summary collapse
- #chdir(raw_path) ⇒ Object
- #directory?(filename = @@filename) ⇒ Boolean
- #glob(s) ⇒ Object
-
#initialize ⇒ DRbFileClientReadWrite
constructor
A new instance of DRbFileClientReadWrite.
- #mkdir(raw_path) ⇒ Object
- #mkdir_p(raw_path) ⇒ Object
- #pwd ⇒ Object
- #rm(path) ⇒ Object
- #rm_r(path, force: false) ⇒ Object
- #touch(s, mtime: Time.now) ⇒ Object
- #write(filename = @@filename, s) ⇒ Object
Constructor Details
#initialize ⇒ DRbFileClientReadWrite
Returns a new instance of DRbFileClientReadWrite.
11 12 13 14 15 |
# File 'lib/drb_fileclient-readwrite.rb', line 11 def initialize() @@directory ||= nil @@file ||= nil @@uri_prefix ||= nil end |
Instance Method Details
#chdir(raw_path) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/drb_fileclient-readwrite.rb', line 17 def chdir(raw_path) return Dir.chdir raw_path unless @@directory or raw_path =~ /^dfs:\/\// if raw_path[0] == '/' then directory = raw_path[1..-1] elsif raw_path =~ /^dfs:\/\// @@file, directory, @@uri_prefix = parse_path(raw_path) else directory = File.join(@@directory, raw_path) end if @@file.exist? directory then @@directory = directory else 'No such file or directory' end end |
#directory?(filename = @@filename) ⇒ Boolean
37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/drb_fileclient-readwrite.rb', line 37 def directory?(filename=@@filename) return File.directory? filename unless @@directory or filename =~ /^dfs:\/\// if filename =~ /^dfs:\/\// then @@file, filename2 = parse_path(filename) else filename2 = File.join(@@directory, filename) end @@file.directory?(filename2) end |
#glob(s) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/drb_fileclient-readwrite.rb', line 52 def glob(s) if s =~ /^dfs:\/\// then @@file, s2 = parse_path(s) else s2 = File.join(@@directory, s) end @@file.glob s2 end |
#mkdir(raw_path) ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/drb_fileclient-readwrite.rb', line 64 def mkdir(raw_path) unless @@directory or raw_path =~ /^dfs:\/\// then return FileUtils.mkdir raw_path end if raw_path =~ /^dfs:\/\// then @@file, filepath = parse_path(raw_path) else if @@uri_prefix then @@file, filepath = parse_path(File.join(@@uri_prefix, @@directory, raw_path)) else filepath = File.join(@@directory, raw_path) end end @@file.mkdir filepath end |
#mkdir_p(raw_path) ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/drb_fileclient-readwrite.rb', line 86 def mkdir_p(raw_path) unless @@directory or raw_path =~ /^dfs:\/\// then return FileUtils.mkdir_p raw_path end if raw_path =~ /^dfs:\/\// then @@file, filepath = parse_path(raw_path) else if @@uri_prefix then @@file, filepath = parse_path(File.join(@@uri_prefix, @@directory, raw_path)) else filepath = File.join(@@directory, raw_path) end end puts 'drb_fileclient-readwrite inside mkdir_p: ' + filepath.inspect @@file.mkdir_p filepath end |
#pwd ⇒ Object
109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/drb_fileclient-readwrite.rb', line 109 def pwd() puts 'inside pwd' puts '@@directory: ' + @@directory.inspect puts '@@file: ' + @@file.inspect return Dir.pwd unless @@directory '/' + @@directory if @@file end |
#rm(path) ⇒ Object
121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/drb_fileclient-readwrite.rb', line 121 def rm(path) return FileUtils.rm path unless @@directory or path =~ /^dfs:\/\// if path =~ /^dfs:\/\// then @@file, path2 = parse_path( path) else path2 = File.join(@@directory, path) end @@file.rm path2 end |
#rm_r(path, force: false) ⇒ Object
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
# File 'lib/drb_fileclient-readwrite.rb', line 135 def rm_r(path, force: false) unless @@directory or path =~ /^dfs:\/\// then return FileUtils.rm_r(path, force: force) end if path =~ /^dfs:\/\// then @@file, path2 = parse_path( path) else path2 = File.join(@@directory, path) end @@file.rm_r(path2, force: force) end |
#touch(s, mtime: Time.now) ⇒ Object
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 |
# File 'lib/drb_fileclient-readwrite.rb', line 151 def touch(s, mtime: Time.now) unless @@directory or s =~ /^dfs:\/\// then return FileUtils.touch(s, mtime: mtime) end if s =~ /^dfs:\/\// then @@file, s2 = parse_path(s) else s2 = File.join(@@directory, s) end @@file.touch s2, mtime: mtime end |
#write(filename = @@filename, s) ⇒ Object
167 168 169 170 171 172 173 174 175 176 177 178 179 |
# File 'lib/drb_fileclient-readwrite.rb', line 167 def write(filename=@@filename, s) return File.write filename, s unless @@directory or filename =~ /^dfs:\/\// if filename =~ /^dfs:\/\// then @@file, path = parse_path(filename) else path = File.join(@@directory, filename) end @@file.write path, s end |