basename(*args)
click to toggle source
def self.basename(*args)
RealFile.basename(*args)
end
const_missing(name)
click to toggle source
def self.const_missing(name)
RealFile.const_get(name)
end
delete(file_name, *additional_file_names)
click to toggle source
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
directory?(path)
click to toggle source
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
def self.dirname(path)
RealFile.dirname(path)
end
exist?(path)
click to toggle source
def self.exist?(path)
!!FileSystem.find(path)
end
expand_path(*args)
click to toggle source
def self.expand_path(*args)
RealFile.expand_path(*args)
end
extname(path)
click to toggle source
def self.extname(path)
RealFile.extname(path)
end
file?(path)
click to toggle source
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
def self.join(*parts)
parts * PATH_SEPARATOR
end
link(source, dest)
click to toggle source
def self.link(source, dest)
if directory?(source)
raise Errno::EPERM, "Operation not permitted - #{source} or #{dest}"
end
if !exists?(source)
raise Errno::ENOENT, "No such file or directory - #{source} or #{dest}"
end
if exists?(dest)
raise Errno::EEXIST, "File exists - #{source} or #{dest}"
end
source = FileSystem.find(source)
dest = FileSystem.add(dest, source.entry.clone)
source.link(dest)
0
end
mtime(path)
click to toggle source
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
def initialize(path, mode = READ_ONLY, perm = nil)
@path = path
@mode = mode
@file = FileSystem.find(path)
@open = true
check_modes!
file_creation_mode? ? create_missing_file : check_file_existence!
@stream = StringIO.new(@file.content, mode)
end
open(path, mode=READ_ONLY, perm = 0644) { |new(path, mode, perm)| ... }
click to toggle source
def self.open(path, mode=READ_ONLY, perm = 0644)
if block_given?
yield new(path, mode, perm)
else
new(path, mode, perm)
end
end
read(path)
click to toggle source
def self.read(path)
file = new(path)
if file.exists?
file.read
else
raise Errno::ENOENT
end
end
readable?(path)
Assuming that everyone can read and write files
readlines(path)
click to toggle source
def self.readlines(path)
read(path).split("\n")
end
readlink(path)
click to toggle source
def self.readlink(path)
symlink = FileSystem.find(path)
FileSystem.find(symlink.target).to_s
end
size(path)
click to toggle source
def self.size(path)
read(path).length
end
size?(path)
click to toggle source
def self.size?(path)
if exists?(path) && !size(path).zero?
true
else
nil
end
end
stat(file)
click to toggle source
def self.stat(file)
File::Stat.new(file)
end
symlink(source, dest)
click to toggle source
def self.symlink(source, dest)
FileUtils.ln_s(source, dest)
end
symlink?(path)
click to toggle source
def self.symlink?(path)
if path.respond_to? :entry
path.is_a? FakeSymlink
else
FileSystem.find(path).is_a? FakeSymlink
end
end
unlink(file_name, *additional_file_names)