Parent

Namespace

Files

FakeFS::File

Attributes

path[R]

Public Class Methods

basename(*args) click to toggle source
# File lib/fakefs/file.rb, line 130
def self.basename(*args)
  RealFile.basename(*args)
end
const_missing(name) click to toggle source
# File lib/fakefs/file.rb, line 96
def self.const_missing(name)
  RealFile.const_get(name)
end
ctime(path) click to toggle source
# File lib/fakefs/file.rb, line 64
def self.ctime(path)
  if exists?(path)
    FileSystem.find(path).ctime
  else
    raise Errno::ENOENT
  end
end
delete(file_name, *additional_file_names) click to toggle source
# File lib/fakefs/file.rb, line 193
def self.delete(file_name, *additional_file_names)
  if !exists?(file_name)
    raise Errno::ENOENT, "No such file or directory - #{file_name}"
  end

  FileUtils.rm(file_name)

  additional_file_names.each do |file_name|
    FileUtils.rm(file_name)
  end

  additional_file_names.size + 1
end
Also aliased as: unlink
directory?(path) click to toggle source
# File lib/fakefs/file.rb, line 100
def self.directory?(path)
  if path.respond_to? :entry
    path.entry.is_a? FakeDir
  else
    result = FileSystem.find(path)
    result ? result.entry.is_a?(FakeDir) : false
  end
end
dirname(path) click to toggle source
# File lib/fakefs/file.rb, line 134
def self.dirname(path)
  RealFile.dirname(path)
end
exist?(path) click to toggle source
# File lib/fakefs/file.rb, line 39
def self.exist?(path)
  if(File.symlink?(path)) then
    referent = File.expand_path(File.readlink(path), File.dirname(path))
    exist?(referent)
  else
    !!FileSystem.find(path)
  end
end
Also aliased as: exists?, readable?, writable?
exists?(path) click to toggle source
Alias for: exist?
expand_path(*args) click to toggle source
# File lib/fakefs/file.rb, line 126
def self.expand_path(*args)
  RealFile.expand_path(*args)
end
extname(path) click to toggle source
# File lib/fakefs/file.rb, line 31
def self.extname(path)
  RealFile.extname(path)
end
file?(path) click to toggle source
# File lib/fakefs/file.rb, line 117
def self.file?(path)
  if path.respond_to? :entry
    path.entry.is_a? FakeFile
  else
    result = FileSystem.find(path)
    result ? result.entry.is_a?(FakeFile) : false
  end
end
join(*parts) click to toggle source
# File lib/fakefs/file.rb, line 35
def self.join(*parts)
  RealFile.join(parts)
end
lstat(file) click to toggle source
# File lib/fakefs/file.rb, line 219
def self.lstat(file)
  File::Stat.new(file, true)
end
mtime(path) click to toggle source
# File lib/fakefs/file.rb, line 56
def self.mtime(path)
  if exists?(path)
    FileSystem.find(path).mtime
  else
    raise Errno::ENOENT
  end
end
new(path, mode = READ_ONLY, perm = nil) click to toggle source
# File lib/fakefs/file.rb, line 265
def initialize(path, mode = READ_ONLY, perm = nil)
  @path = path
  @mode = mode
  @file = FileSystem.find(path)
  @autoclose = true

  check_modes!

  file_creation_mode? ? create_missing_file : check_file_existence!

  super(@file.content, mode)
end
read(path) click to toggle source
# File lib/fakefs/file.rb, line 143
def self.read(path)
  file = new(path)
  if file.exists?
    file.read
  else
    raise Errno::ENOENT
  end
end
readable?(path) click to toggle source

Assuming that everyone can read and write files

Alias for: exist?
readlines(path) click to toggle source
# File lib/fakefs/file.rb, line 152
def self.readlines(path)
  read(path).split("\n")
end
rename(source, dest) click to toggle source
# File lib/fakefs/file.rb, line 156
def self.rename(source, dest)
  if directory?(source) && file?(dest)
    raise Errno::ENOTDIR, "Not a directory - #{source} or #{dest}"
  elsif file?(source) && directory?(dest)
    raise Errno::EISDIR, "Is a directory - #{source} or #{dest}"
  end

  if target = FileSystem.find(source)
    FileSystem.add(dest, target.entry.clone)
    FileSystem.delete(source)
  else
    raise Errno::ENOENT,  "No such file or directory - #{source} or #{dest}"
  end

  0
end
size(path) click to toggle source
# File lib/fakefs/file.rb, line 84
def self.size(path)
  read(path).length
end
size?(path) click to toggle source
# File lib/fakefs/file.rb, line 88
def self.size?(path)
  if exists?(path) && !size(path).zero?
    true
  else
    nil
  end
end
split(path) click to toggle source
# File lib/fakefs/file.rb, line 223
def self.split(path)
  return RealFile.split(path)
end
stat(file) click to toggle source
# File lib/fakefs/file.rb, line 215
def self.stat(file)
  File::Stat.new(file)
end
utime(atime, mtime, *paths) click to toggle source
# File lib/fakefs/file.rb, line 72
def self.utime(atime, mtime, *paths)
  paths.each do |path|
    if exists?(path)
      FileSystem.find(path).mtime = mtime
    else
      raise Errno::ENOENT
    end
  end

  paths.size
end
writable?(path) click to toggle source
Alias for: exist?

Public Instance Methods

atime() click to toggle source
# File lib/fakefs/file.rb, line 328
def atime
  raise NotImplementedError
end
autoclose?() click to toggle source
# File lib/fakefs/file.rb, line 373
def autoclose?
  @autoclose
end
binmode?() click to toggle source
# File lib/fakefs/file.rb, line 353
def binmode?
  raise NotImplementedError
end
chmod(mode_int) click to toggle source
# File lib/fakefs/file.rb, line 332
def chmod(mode_int)
  raise NotImplementedError
end
chown(owner_int, group_int) click to toggle source
# File lib/fakefs/file.rb, line 336
def chown(owner_int, group_int)
  raise NotImplementedError
end
close_on_exec=(bool) click to toggle source
# File lib/fakefs/file.rb, line 357
def close_on_exec=(bool)
  raise NotImplementedError
end
close_on_exec?() click to toggle source
# File lib/fakefs/file.rb, line 361
def close_on_exec?
  raise NotImplementedError
end
ctime() click to toggle source
# File lib/fakefs/file.rb, line 340
def ctime
  self.class.ctime(@path)
end
exists?() click to toggle source
# File lib/fakefs/file.rb, line 278
def exists?
  true
end
flock(locking_constant) click to toggle source
# File lib/fakefs/file.rb, line 344
def flock(locking_constant)
  raise NotImplementedError
end
ioctl(integer_cmd, arg) click to toggle source
# File lib/fakefs/file.rb, line 293
def ioctl(integer_cmd, arg)
  raise NotImplementedError
end
lstat() click to toggle source
# File lib/fakefs/file.rb, line 305
def lstat
  self.class.lstat(@path)
end
mtime() click to toggle source
# File lib/fakefs/file.rb, line 348
def mtime
  self.class.mtime(@path)
end
read_nonblock(maxlen, outbuf = nil) click to toggle source
# File lib/fakefs/file.rb, line 297
def read_nonblock(maxlen, outbuf = nil)
  raise NotImplementedError
end
readpartial(maxlen, outbuf = nil) click to toggle source
# File lib/fakefs/file.rb, line 324
def readpartial(maxlen, outbuf = nil)
  raise NotImplementedError
end
size() click to toggle source
# File lib/fakefs/file.rb, line 379
def size
  File.size(@path)
end
stat() click to toggle source
# File lib/fakefs/file.rb, line 301
def stat
  self.class.stat(@path)
end
sysseek(position, whence = SEEK_SET) click to toggle source
# File lib/fakefs/file.rb, line 309
def sysseek(position, whence = SEEK_SET)
  seek(position, whence)
  pos
end
to_io() click to toggle source
# File lib/fakefs/file.rb, line 316
def to_io
  self
end
to_path() click to toggle source
# File lib/fakefs/file.rb, line 365
def to_path
  @path
end
write_nonblock(string) click to toggle source
# File lib/fakefs/file.rb, line 320
def write_nonblock(string)
  raise NotImplementedError
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.