Class: FakeFS::FakeInode

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

Overview

Inode class

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file_owner) ⇒ FakeInode

Returns a new instance of FakeInode.



7
8
9
10
11
# File 'lib/fakefs/fake/inode.rb', line 7

def initialize(file_owner)
  @content = ''.encode(Encoding.default_external)
  @links = [file_owner]
  assign_inode_num
end

Class Attribute Details

.freed_inodesObject

Returns the value of attribute freed_inodes.



19
20
21
# File 'lib/fakefs/fake/inode.rb', line 19

def freed_inodes
  @freed_inodes
end

.next_inode_numObject

Returns the value of attribute next_inode_num.



20
21
22
# File 'lib/fakefs/fake/inode.rb', line 20

def next_inode_num
  @next_inode_num
end

Instance Attribute Details

#contentObject

Returns the value of attribute content.



13
14
15
# File 'lib/fakefs/fake/inode.rb', line 13

def content
  @content
end

#inode_numObject

Returns the value of attribute inode_num.



15
16
17
# File 'lib/fakefs/fake/inode.rb', line 15

def inode_num
  @inode_num
end

Returns the value of attribute links.



14
15
16
# File 'lib/fakefs/fake/inode.rb', line 14

def links
  @links
end

Class Method Details

.clear_inode_info_for_testsObject

This method should only be used for tests When called, it will reset the current inode information of the FakeFS



24
25
26
27
# File 'lib/fakefs/fake/inode.rb', line 24

def clear_inode_info_for_tests
  self.freed_inodes = []
  self.next_inode_num = 0
end

Instance Method Details

#assign_inode_numObject



30
31
32
33
34
35
36
# File 'lib/fakefs/fake/inode.rb', line 30

def assign_inode_num
  if (@inode_num = self.class.freed_inodes.shift)
  else
    @inode_num = self.class.next_inode_num
    self.class.next_inode_num += 1
  end
end

#cloneObject



51
52
53
54
55
56
# File 'lib/fakefs/fake/inode.rb', line 51

def clone
  clone = super
  clone.content = content.dup
  clone.assign_inode_num
  clone
end

#free_inode_numObject



38
39
40
# File 'lib/fakefs/fake/inode.rb', line 38

def free_inode_num
  self.class.freed_inodes.push(@inode_num)
end


42
43
44
45
# File 'lib/fakefs/fake/inode.rb', line 42

def link(file)
  links << file unless links.include?(file)
  file.inode = self
end


47
48
49
# File 'lib/fakefs/fake/inode.rb', line 47

def unlink(file)
  links.delete(file)
end