class FakeFS::Dir

Public Class Methods

[](pattern) click to toggle source
# File lib/fakefs/dir.rb, line 55
def self.[](pattern)
  glob(pattern)
end
chdir(dir, &blk) click to toggle source
# File lib/fakefs/dir.rb, line 59
def self.chdir(dir, &blk)
  FileSystem.chdir(dir, &blk)
end
chroot(string) click to toggle source
# File lib/fakefs/dir.rb, line 63
def self.chroot(string)
  # Not implemented yet
end
delete(string) click to toggle source
# File lib/fakefs/dir.rb, line 67
def self.delete(string)
  raise SystemCallError, "No such file or directory - #{string}" unless FileSystem.find(string).values.empty?
  FileSystem.delete(string)
end
Also aliased as: rmdir, unlink
entries(dirname) click to toggle source
# File lib/fakefs/dir.rb, line 72
def self.entries(dirname)
  raise SystemCallError, dirname unless FileSystem.find(dirname)
  Dir.new(dirname).map { |file| File.basename(file) }
end
foreach(dirname) { |file| ... } click to toggle source
# File lib/fakefs/dir.rb, line 77
def self.foreach(dirname, &block)
  Dir.open(dirname) { |file| yield file }
end
getwd()
Alias for: pwd
glob(pattern) click to toggle source
# File lib/fakefs/dir.rb, line 81
def self.glob(pattern)
  [FileSystem.find(pattern) || []].flatten.map{|e| e.to_s}.sort
end
mkdir(string, integer = 0) click to toggle source
# File lib/fakefs/dir.rb, line 85
def self.mkdir(string, integer = 0)
  parent = string.split('/')
  parent.pop
  raise Errno::ENOENT, "No such file or directory - #{string}" unless parent.join == "" || FileSystem.find(parent.join('/'))
  FileUtils.mkdir_p(string)
end
new(string) click to toggle source
# File lib/fakefs/dir.rb, line 5
def initialize(string)
  raise Errno::ENOENT, string unless FileSystem.find(string)
  @path = string
  @open = true
  @pointer = 0
  @contents = [ '.', '..', ] + FileSystem.find(@path).values
end
open(string) { |file| ... } click to toggle source
# File lib/fakefs/dir.rb, line 92
def self.open(string, &block)
  if block_given?
    Dir.new(string).each { |file| yield(file) }
  else
    Dir.new(string)
  end
end
pwd() click to toggle source
# File lib/fakefs/dir.rb, line 104
def self.pwd
  FileSystem.current_dir.to_s
end
Also aliased as: getwd
rmdir(string)
Alias for: delete
tmpdir() click to toggle source
# File lib/fakefs/dir.rb, line 100
def self.tmpdir
  '/tmp'
end

Public Instance Methods

close() click to toggle source
# File lib/fakefs/dir.rb, line 13
def close
  @open = false
  @pointer = nil
  @contents = nil
  nil
end
each() { |f| ... } click to toggle source
# File lib/fakefs/dir.rb, line 20
def each(&block)
  while f = read
    yield f
  end
end
path() click to toggle source
# File lib/fakefs/dir.rb, line 26
def path
  @path
end
pos() click to toggle source
# File lib/fakefs/dir.rb, line 30
def pos
  @pointer
end
pos=(integer) click to toggle source
# File lib/fakefs/dir.rb, line 34
def pos=(integer)
  @pointer = integer
end
read() click to toggle source
# File lib/fakefs/dir.rb, line 38
def read
  raise IOError, "closed directory" if @pointer == nil
  n = @contents[@pointer]
  @pointer += 1
  n.to_s.gsub(path + '/', '') if n
end
rewind() click to toggle source
# File lib/fakefs/dir.rb, line 45
def rewind
  @pointer = 0
end
seek(integer) click to toggle source
# File lib/fakefs/dir.rb, line 49
def seek(integer)
  raise IOError, "closed directory" if @pointer == nil
  @pointer = integer
  @contents[integer]
end