Class: FileSystem::MockFileSystem::MockDir
- Inherits:
-
Hash
- Object
- Hash
- FileSystem::MockFileSystem::MockDir
show all
- Includes:
- Node
- Defined in:
- lib/filesystem.rb
Overview
Instance Attribute Summary
Attributes included from Node
#mtime, #name, #parent, #permissions
Instance Method Summary
collapse
Constructor Details
#initialize(name, parent = nil) ⇒ MockDir
Returns a new instance of MockDir.
223
224
225
226
227
|
# File 'lib/filesystem.rb', line 223
def initialize( name, parent = nil )
super( {} )
@name, @parent = name, parent
@mtime = Time.now
end
|
Instance Method Details
#[]=(name, child) ⇒ Object
229
230
231
232
|
# File 'lib/filesystem.rb', line 229
def []= ( name, child )
super
@mtime = child.mtime
end
|
#delete(child = nil) ⇒ Object
234
235
236
|
# File 'lib/filesystem.rb', line 234
def delete( child = nil )
child ? super( child.name ) : parent.delete( self )
end
|
#entries ⇒ Object
238
|
# File 'lib/filesystem.rb', line 238
def entries; %w( . .. ).concat( keys ); end
|
#fill_dir(dirname) ⇒ Object
255
256
257
258
259
260
261
262
263
|
# File 'lib/filesystem.rb', line 255
def fill_dir( dirname )
dir = self[dirname]
if dir.nil?
dir = MockDir.new( dirname, self )
self[dirname] = dir
@mtime = dir.mtime
end
dir
end
|
#fill_path(dirname) ⇒ Object
265
266
267
268
269
270
271
272
|
# File 'lib/filesystem.rb', line 265
def fill_path( dirname )
if dirname.size > 1
dir = fill_dir( dirname.first )
dir.fill_path( dirname[1..-1] )
else
fill_dir( dirname )
end
end
|
#get_node(dirname) ⇒ Object
240
241
242
243
244
245
246
247
248
249
250
251
252
253
|
# File 'lib/filesystem.rb', line 240
def get_node( dirname )
if dirname.first == '..'
self.parent.get_node( dirname[1..-1] )
elsif dirname.first == '.'
self.get_node( dirname[1..-1] )
elsif dirname.size > 1
subdir = self[dirname.first]
subdir ? subdir.get_node( dirname[1..-1] ) : ( raise Errno::ENOENT )
elsif dirname == ''
self
else
self[dirname.strip] or ( raise Errno::ENOENT )
end
end
|
#mkdir(dirname) ⇒ Object
274
|
# File 'lib/filesystem.rb', line 274
def mkdir( dirname ); fill_path( Path.new( dirname ) ); end
|