Class: Pione::Util::FTPOnMemoryFS
- Inherits:
-
FTPFileSystem
- Object
- FTPFileSystem
- Pione::Util::FTPOnMemoryFS
- Defined in:
- lib/pione/util/ftp-server.rb
Overview
OnMemoryFS is a virtual file system on memory.
Constant Summary collapse
- ROOT =
Pathname.new("/")
Instance Attribute Summary collapse
-
#directory ⇒ Object
readonly
Returns the value of attribute directory.
-
#file ⇒ Object
readonly
Returns the value of attribute file.
-
#mtime ⇒ Object
readonly
Returns the value of attribute mtime.
Instance Method Summary collapse
-
#clear ⇒ void
Clear file system items.
- #delete_file(path) ⇒ Object
- #directory?(path) ⇒ Boolean
- #entries(path) ⇒ Object
- #file?(path) ⇒ Boolean
- #get_file(path) ⇒ Object
- #get_mtime(path) ⇒ Object
- #get_size(path) ⇒ Object
-
#initialize ⇒ FTPOnMemoryFS
constructor
A new instance of FTPOnMemoryFS.
- #mkdir(path) ⇒ Object
- #mv(from_path, to_path) ⇒ Object
- #put_file(path, data) ⇒ Object
- #rmdir(path) ⇒ Object
Methods inherited from FTPFileSystem
Constructor Details
#initialize ⇒ FTPOnMemoryFS
Returns a new instance of FTPOnMemoryFS.
148 149 150 151 152 |
# File 'lib/pione/util/ftp-server.rb', line 148 def initialize @directory = {ROOT => Set.new} @file = {} @mtime = {} end |
Instance Attribute Details
#directory ⇒ Object (readonly)
Returns the value of attribute directory.
144 145 146 |
# File 'lib/pione/util/ftp-server.rb', line 144 def directory @directory end |
#file ⇒ Object (readonly)
Returns the value of attribute file.
145 146 147 |
# File 'lib/pione/util/ftp-server.rb', line 145 def file @file end |
#mtime ⇒ Object (readonly)
Returns the value of attribute mtime.
146 147 148 |
# File 'lib/pione/util/ftp-server.rb', line 146 def mtime @mtime end |
Instance Method Details
#clear ⇒ void
This method returns an undefined value.
Clear file system items.
157 158 159 160 161 162 |
# File 'lib/pione/util/ftp-server.rb', line 157 def clear @directory.clear @directory[ROOT] = Set.new @file.clear @mtime.clear end |
#delete_file(path) ⇒ Object
182 183 184 185 186 |
# File 'lib/pione/util/ftp-server.rb', line 182 def delete_file(path) @directory[path.dirname].delete(path.basename) @file.delete(path) @mtime.delete(path) end |
#directory?(path) ⇒ Boolean
164 165 166 |
# File 'lib/pione/util/ftp-server.rb', line 164 def directory?(path) @directory.has_key?(path) end |
#entries(path) ⇒ Object
196 197 198 |
# File 'lib/pione/util/ftp-server.rb', line 196 def entries(path) @directory[path] end |
#file?(path) ⇒ Boolean
168 169 170 |
# File 'lib/pione/util/ftp-server.rb', line 168 def file?(path) @file.has_key?(path) end |
#get_file(path) ⇒ Object
172 173 174 |
# File 'lib/pione/util/ftp-server.rb', line 172 def get_file(path) @file[path] end |
#get_mtime(path) ⇒ Object
192 193 194 |
# File 'lib/pione/util/ftp-server.rb', line 192 def get_mtime(path) @mtime[path] end |
#get_size(path) ⇒ Object
188 189 190 |
# File 'lib/pione/util/ftp-server.rb', line 188 def get_size(path) @file[path].bytesize end |
#mkdir(path) ⇒ Object
200 201 202 203 204 205 |
# File 'lib/pione/util/ftp-server.rb', line 200 def mkdir(path) @directory[path] = Set.new unless path == path.dirname @directory[path.dirname] << path.basename end end |
#mv(from_path, to_path) ⇒ Object
214 215 216 217 218 219 220 221 |
# File 'lib/pione/util/ftp-server.rb', line 214 def mv(from_path, to_path) @directory[to_path.dirname] << from_path.basename @directory[from_path.dirname].delete(from_path.basename) @file[to_path] = @file[from_path] @file.delete(from_path) @mtime[to_path] = @file[from_path] @mtime.delete(to_path) end |
#put_file(path, data) ⇒ Object
176 177 178 179 180 |
# File 'lib/pione/util/ftp-server.rb', line 176 def put_file(path, data) @directory[path.dirname] << path.basename @file[path] = File.read(data) @mtime[path] = Time.now end |
#rmdir(path) ⇒ Object
207 208 209 210 211 212 |
# File 'lib/pione/util/ftp-server.rb', line 207 def rmdir(path) @directory.delete(path) unless path == path.dirname @directory[path.dirname].delete(path.basename) end end |