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.



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

def initialize(name = nil, parent = nil)
  @name   = name
  @parent = parent
  @ctime  = Time.now
  @mtime  = @ctime
end

Instance Attribute Details

#ctimeObject (readonly)

Returns the value of attribute ctime.



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

def ctime
  @ctime
end

#mtimeObject (readonly)

Returns the value of attribute mtime.



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

def mtime
  @mtime
end

#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



21
22
23
24
25
26
27
28
# File 'lib/fakefs/fake/dir.rb', line 21

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

#delete(node = self) ⇒ Object



40
41
42
43
44
45
46
# File 'lib/fakefs/fake/dir.rb', line 40

def delete(node = self)
  if node == self
    parent.delete(self)
  else
    super(node.name)
  end
end

#entryObject



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

def entry
  self
end

#inspectObject



17
18
19
# File 'lib/fakefs/fake/dir.rb', line 17

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

#to_sObject



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

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