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.



486
487
488
489
# File 'lib/mockfs.rb', line 486

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.



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

def contents=(value)
  @contents = value
end

Instance Method Details

#cloneObject



491
492
493
494
495
496
497
# File 'lib/mockfs.rb', line 491

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

#closeObject



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

def close; rewind; end

#deleteObject



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

def delete; parent.delete( self ); end

#gets(sep_string = $/) ⇒ Object



503
504
505
# File 'lib/mockfs.rb', line 503

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

#rewindObject



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

def rewind; @contents ? super : nil; end