Class: VirtualFS::Dir

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/virtualfs/dir.rb

Instance Method Summary collapse

Constructor Details

#initialize(path, backend) ⇒ Dir

Returns a new instance of Dir.



5
6
7
8
9
# File 'lib/virtualfs/dir.rb', line 5

def initialize(path, backend)
  @path = path
  @realpath = VirtualFS.realpath(path)
  @backend = backend
end

Instance Method Details

#directory?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/virtualfs/dir.rb', line 20

def directory?
  true
end

#each(&block) ⇒ Object



32
33
34
# File 'lib/virtualfs/dir.rb', line 32

def each(&block)
  entries.each(&block)
end

#entriesObject



24
25
26
# File 'lib/virtualfs/dir.rb', line 24

def entries
  @backend.entries @realpath
end

#glob(pattern) ⇒ Object Also known as: []



28
29
30
# File 'lib/virtualfs/dir.rb', line 28

def glob(pattern)
  @backend.glob pattern, @realpath
end

#inspectObject



36
37
38
39
40
41
42
43
44
# File 'lib/virtualfs/dir.rb', line 36

def inspect
  if ['.','..'].include? name
    p = @path
  else
    p = @realpath
  end

  "<#{@backend.class.name} '#{p}' (dir)>"
end

#nameObject



15
16
17
18
# File 'lib/virtualfs/dir.rb', line 15

def name
  name = @path.rpartition('/').last
  name.empty? ? '/' : name
end

#pathObject



11
12
13
# File 'lib/virtualfs/dir.rb', line 11

def path
  @realpath
end