Class: MockFS::MockFileSystem::MockFile

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

Overview

:nodoc:

Instance Attribute Summary collapse

Attributes included from Node

#mtime, #name, #parent, #permissions

Instance Method Summary collapse

Methods included from Node

#readable?

Constructor Details

#initialize(parent, name, contents) ⇒ MockFile

Returns a new instance of MockFile.



478
479
480
481
# File 'lib/mockfs.rb', line 478

def initialize( parent, name, contents )
	@name = name; @parent = parent; @mtime = Time.now; @contents = contents
	super( StringIO.new( contents ) ) if contents
end

Instance Attribute Details

#contents=(value) ⇒ Object (writeonly)

Sets the attribute contents

Parameters:

  • value

    the value to set the attribute contents to.



476
477
478
# File 'lib/mockfs.rb', line 476

def contents=(value)
  @contents = value
end

Instance Method Details

#cloneObject



483
484
485
486
487
488
# File 'lib/mockfs.rb', line 483

def clone
	rewind
	clone = self.class.new( @parent, @name, gets( nil ) )
	clone.mtime = @mtime
	clone
end

#closeObject



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

def close; rewind; end

#deleteObject



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

def delete; parent.delete( self ); end

#gets(sep_string = $/) ⇒ Object



494
495
496
# File 'lib/mockfs.rb', line 494

def gets( sep_string = $/ )
	@contents ? super( sep_string ) : nil
end

#rewindObject



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

def rewind; @contents ? super : nil; end