Class: FakeFS::FakeFile

Inherits:
Object
  • Object
show all
Defined in:
lib/fakefs/fake/file.rb

Overview

Fake file class

Defined Under Namespace

Classes: Inode

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name = nil, parent = nil) ⇒ FakeFile

Returns a new instance of FakeFile.



36
37
38
39
40
41
42
43
44
45
46
# File 'lib/fakefs/fake/file.rb', line 36

def initialize(name = nil, parent = nil)
  @name   = name
  @parent = parent
  @inode  = Inode.new(self)
  @ctime  = Time.now
  @mtime  = @ctime
  @atime  = @ctime
  @mode   = 0100000 + (0666 - File.umask)
  @uid    = Process.uid
  @gid    = Process.gid
end

Instance Attribute Details

#atimeObject

Returns the value of attribute atime.



4
5
6
# File 'lib/fakefs/fake/file.rb', line 4

def atime
  @atime
end

#contentObject

Returns the value of attribute content.



4
5
6
# File 'lib/fakefs/fake/file.rb', line 4

def content
  @content
end

#ctimeObject (readonly)

Returns the value of attribute ctime.



5
6
7
# File 'lib/fakefs/fake/file.rb', line 5

def ctime
  @ctime
end

#gidObject

Returns the value of attribute gid.



4
5
6
# File 'lib/fakefs/fake/file.rb', line 4

def gid
  @gid
end

#inodeObject

Returns the value of attribute inode.



48
49
50
# File 'lib/fakefs/fake/file.rb', line 48

def inode
  @inode
end

#modeObject

Returns the value of attribute mode.



4
5
6
# File 'lib/fakefs/fake/file.rb', line 4

def mode
  @mode
end

#mtimeObject

Returns the value of attribute mtime.



4
5
6
# File 'lib/fakefs/fake/file.rb', line 4

def mtime
  @mtime
end

#nameObject

Returns the value of attribute name.



4
5
6
# File 'lib/fakefs/fake/file.rb', line 4

def name
  @name
end

#parentObject

Returns the value of attribute parent.



4
5
6
# File 'lib/fakefs/fake/file.rb', line 4

def parent
  @parent
end

#uidObject

Returns the value of attribute uid.



4
5
6
# File 'lib/fakefs/fake/file.rb', line 4

def uid
  @uid
end

Instance Method Details

#clone(parent = nil) ⇒ Object



66
67
68
69
70
71
# File 'lib/fakefs/fake/file.rb', line 66

def clone(parent = nil)
  clone = super()
  clone.parent = parent if parent
  clone.inode  = inode.clone
  clone
end

#deleteObject



86
87
88
89
# File 'lib/fakefs/fake/file.rb', line 86

def delete
  inode.unlink(self)
  parent.delete(self)
end

#entryObject



73
74
75
# File 'lib/fakefs/fake/file.rb', line 73

def entry
  self
end

#inspectObject



77
78
79
80
# File 'lib/fakefs/fake/file.rb', line 77

def inspect
  "(FakeFile name:#{name.inspect} " \
  "parent:#{parent.to_s.inspect} size:#{content.size})"
end


62
63
64
# File 'lib/fakefs/fake/file.rb', line 62

def link(other_file)
  @inode.link(other_file)
end


58
59
60
# File 'lib/fakefs/fake/file.rb', line 58

def links
  @inode.links
end

#to_sObject



82
83
84
# File 'lib/fakefs/fake/file.rb', line 82

def to_s
  File.join(parent.to_s, name)
end