Class: FakeFS::FakeDir

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of FakeDir.



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

def initialize(name = nil, parent = nil)
  @name = name
  @parent = parent
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



3
4
5
# File 'lib/fakefs/fake/dir.rb', line 3

def name
  @name
end

#parentObject

Returns the value of attribute parent.



3
4
5
# File 'lib/fakefs/fake/dir.rb', line 3

def parent
  @parent
end

Instance Method Details

#clone(parent = nil) ⇒ Object



18
19
20
21
22
23
24
25
# File 'lib/fakefs/fake/dir.rb', line 18

def clone(parent = nil)
  clone = Marshal.load(Marshal.dump(self))
  clone.each do |key, value|
    value.parent = clone
  end
  clone.parent = parent if parent
  clone
end

#entryObject



10
11
12
# File 'lib/fakefs/fake/dir.rb', line 10

def entry
  self
end

#inspectObject



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

def inspect
  "(FakeDir name:#{name.inspect} parent:#{parent.to_s.inspect} size:#{size})"
end

#to_sObject



27
28
29
30
31
32
33
34
35
# File 'lib/fakefs/fake/dir.rb', line 27

def to_s
  if parent && parent.to_s != '.'
    File.join(parent.to_s, name)
  elsif parent && parent.to_s == '.'
    "#{File::PATH_SEPARATOR}#{name}"
  else
    name
  end
end