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.



9
10
11
12
13
# File 'lib/fakefs/fake/inode.rb', line 9

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.



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

def next_inode_num
  @next_inode_num
end

Instance Attribute Details

#contentObject

Returns the value of attribute content.



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

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.



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

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



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

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

Instance Method Details

#assign_inode_numObject



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

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

#cloneObject



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

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

#free_inode_numObject



36
37
38
# File 'lib/fakefs/fake/inode.rb', line 36

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


40
41
42
43
# File 'lib/fakefs/fake/inode.rb', line 40

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


45
46
47
# File 'lib/fakefs/fake/inode.rb', line 45

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