Class: MockFS::MockFileSystem::MockDir

Inherits:
Hash
  • Object
show all
Includes:
Node
Defined in:
lib/mockfs.rb

Overview

:nodoc:

Direct Known Subclasses

MockRoot

Instance Attribute Summary

Attributes included from Node

#mtime, #name, #parent, #permissions

Instance Method Summary collapse

Methods included from Node

#readable?

Constructor Details

#initialize(name, parent = nil) ⇒ MockDir

Returns a new instance of MockDir.



423
424
425
426
427
# File 'lib/mockfs.rb', line 423

def initialize( name, parent = nil )
	super( {} )
	@name, @parent = name, parent
	@mtime = Time.now
end

Instance Method Details

#[]=(name, child) ⇒ Object



429
430
431
432
# File 'lib/mockfs.rb', line 429

def []= ( name, child )
	super
	@mtime = child.mtime
end

#delete(child = nil) ⇒ Object



434
435
436
# File 'lib/mockfs.rb', line 434

def delete( child = nil )
	child ? super( child.name ) : parent.delete( self )
end

#entriesObject



438
# File 'lib/mockfs.rb', line 438

def entries; %w( . .. ).concat( keys ); end

#fill_dir(dirname) ⇒ Object



440
441
442
443
444
445
446
447
448
# File 'lib/mockfs.rb', line 440

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



450
451
452
453
454
455
456
457
458
459
460
461
# File 'lib/mockfs.rb', line 450

def fill_path( dirname )
	if dirname.size > 1
		if dirname.first != '..'
			dir = fill_dir( dirname.first )
			dir.fill_path( dirname[1..-1] )
		else
			parent.fill_path( dirname[1..-1] )
		end
	else
		fill_dir( dirname )
	end
end

#mkdir(dirname) ⇒ Object



463
# File 'lib/mockfs.rb', line 463

def mkdir( dirname ); fill_path( Path.new( dirname ) ); end

#node(dirname) ⇒ Object



465
466
467
468
469
470
471
472
473
474
475
476
477
478
# File 'lib/mockfs.rb', line 465

def node( dirname )
	if dirname.first == '..'
		self.parent.node( dirname[1..-1] )
	elsif dirname.first == '.'
		self.node( dirname[1..-1] )
	elsif dirname.size > 1
		subdir = self[dirname.first]
		subdir ? subdir.node( dirname[1..-1] ) : ( raise Errno::ENOENT )
	elsif dirname == ''
		self
	else
		self[dirname.strip] or ( raise Errno::ENOENT )
	end
end