class MemFs::File
Constants
- ALT_SEPARATOR
- MODE_MAP
- SEPARATOR
- SUCCESS
Attributes
path[R]
Public Class Methods
absolute_path(path, dir_string = fs.pwd)
click to toggle source
# File lib/memfs/file.rb, line 78 def self.absolute_path(path, dir_string = fs.pwd) original_file_class.absolute_path(path, dir_string) end
atime(path)
click to toggle source
# File lib/memfs/file.rb, line 82 def self.atime(path) stat(path).atime end
chmod(mode_int, *paths)
click to toggle source
# File lib/memfs/file.rb, line 86 def self.chmod(mode_int, *paths) paths.each do |path| fs.chmod mode_int, path end end
chown(uid, gid, *paths)
click to toggle source
# File lib/memfs/file.rb, line 92 def self.chown(uid, gid, *paths) paths.each do |path| fs.chown(uid, gid, path) end paths.size end
ctime(path)
click to toggle source
# File lib/memfs/file.rb, line 99 def self.ctime(path) stat(path).ctime end
exists?(path)
click to toggle source
# File lib/memfs/file.rb, line 103 def self.exists?(path) !!fs.find(path) end
Also aliased as: exist?
expand_path(file_name, dir_string = fs.pwd)
click to toggle source
# File lib/memfs/file.rb, line 108 def self.expand_path(file_name, dir_string = fs.pwd) original_file_class.expand_path(file_name, dir_string) end
ftype(path)
click to toggle source
# File lib/memfs/file.rb, line 112 def self.ftype(path) fs.find!(path) && lstat(path).ftype end
identical?(path1, path2)
click to toggle source
# File lib/memfs/file.rb, line 118 def self.identical?(path1, path2) fs.find!(path1).dereferenced === fs.find!(path2).dereferenced rescue Errno::ENOENT false end
lchmod(mode_int, *file_names)
click to toggle source
# File lib/memfs/file.rb, line 124 def self.lchmod(mode_int, *file_names) file_names.each do |file_name| fs.chmod mode_int, file_name end end
lchown(uid, gid, *paths)
click to toggle source
# File lib/memfs/file.rb, line 130 def self.lchown(uid, gid, *paths) chown uid, gid, *paths end
link(old_name, new_name)
click to toggle source
# File lib/memfs/file.rb, line 134 def self.link(old_name, new_name) fs.link old_name, new_name SUCCESS end
lstat(path)
click to toggle source
# File lib/memfs/file.rb, line 139 def self.lstat(path) Stat.new(path) end
mtime(path)
click to toggle source
# File lib/memfs/file.rb, line 143 def self.mtime(path) stat(path).mtime end
new(filename, mode = File::RDONLY, *perm_and_or_opt)
click to toggle source
# File lib/memfs/file.rb, line 237 def initialize(filename, mode = File::RDONLY, *perm_and_or_opt) opt = perm_and_or_opt.last.is_a?(Hash) ? perm_and_or_opt.pop : {} perm_and_or_opt.shift if perm_and_or_opt.any? fail ArgumentError, 'wrong number of arguments (4 for 1..3)' end @path = filename @external_encoding = opt[:external_encoding] && Encoding.find(opt[:external_encoding]) self.closed = false self.opening_mode = str_to_mode_int(mode) fs.touch(filename) if create_file? self.entry = fs.find!(filename) # FIXME: this is an ugly way to ensure a symlink has a target entry.dereferenced if entry.respond_to?(:pos=) entry.pos = 0 end entry.content.clear if truncate_file? end
open(filename, mode = RDONLY, *perm_and_opt) { |file| ... }
click to toggle source
# File lib/memfs/file.rb, line 147 def self.open(filename, mode = RDONLY, *perm_and_opt) file = new(filename, mode, *perm_and_opt) if block_given? yield file else file end ensure file.close if file && block_given? end
readlink(path)
click to toggle source
# File lib/memfs/file.rb, line 159 def self.readlink(path) fs.find!(path).target end
realdirpath(path, dir_string = fs.pwd)
click to toggle source
# File lib/memfs/file.rb, line 163 def self.realdirpath(path, dir_string = fs.pwd) loose_dereference_path(absolute_path(path, dir_string)) end
realpath(path, dir_string = fs.pwd)
click to toggle source
# File lib/memfs/file.rb, line 167 def self.realpath(path, dir_string = fs.pwd) dereference_path(absolute_path(path, dir_string)) end
rename(old_name, new_name)
click to toggle source
# File lib/memfs/file.rb, line 171 def self.rename(old_name, new_name) fs.rename(old_name, new_name) SUCCESS end
reset!()
click to toggle source
# File lib/memfs/file.rb, line 176 def self.reset! @umask = original_file_class.umask end
size(path)
click to toggle source
# File lib/memfs/file.rb, line 180 def self.size(path) fs.find!(path).size end
size?(path)
click to toggle source
# File lib/memfs/file.rb, line 184 def self.size?(path) file = fs.find(path) if file && file.size > 0 file.size else false end end
stat(path)
click to toggle source
# File lib/memfs/file.rb, line 193 def self.stat(path) Stat.new(path, true) end
symlink(old_name, new_name)
click to toggle source
# File lib/memfs/file.rb, line 197 def self.symlink(old_name, new_name) fs.symlink old_name, new_name SUCCESS end
symlink?(path)
click to toggle source
# File lib/memfs/file.rb, line 202 def self.symlink?(path) lstat_query(path, :symlink?) end
truncate(path, length)
click to toggle source
# File lib/memfs/file.rb, line 206 def self.truncate(path, length) fs.find!(path).content.truncate(length) SUCCESS end
umask(integer = nil)
click to toggle source
# File lib/memfs/file.rb, line 211 def self.umask(integer = nil) old_value = @umask || original_file_class.umask @umask = integer if integer old_value end
unlink(*paths)
click to toggle source
# File lib/memfs/file.rb, line 219 def self.unlink(*paths) paths.each do |path| fs.unlink(path) end paths.size end
Also aliased as: delete
utime(atime, mtime, *file_names)
click to toggle source
# File lib/memfs/file.rb, line 227 def self.utime(atime, mtime, *file_names) file_names.each do |file_name| fs.find!(file_name).atime = atime fs.find!(file_name).mtime = mtime end file_names.size end
Private Class Methods
dereference_dir_path(path)
click to toggle source
# File lib/memfs/file.rb, line 311 def self.dereference_dir_path(path) dereference_path(dirname(path)) end
dereference_name(path)
click to toggle source
# File lib/memfs/file.rb, line 301 def self.dereference_name(path) entry = fs.find(path) if entry entry.dereferenced_name else basename(path) end end
dereference_path(path)
click to toggle source
# File lib/memfs/file.rb, line 316 def self.dereference_path(path) fs.find!(path).dereferenced_path end
loose_dereference_path(path)
click to toggle source
# File lib/memfs/file.rb, line 321 def self.loose_dereference_path(path) join(dereference_dir_path(path), dereference_name(path)) end
lstat_query(path, query)
click to toggle source
# File lib/memfs/file.rb, line 337 def self.lstat_query(path, query) response = fs.find(path) && lstat(path).public_send(query) !!response end
original_file_class()
click to toggle source
# File lib/memfs/file.rb, line 326 def self.original_file_class MemFs::OriginalFile end
stat_query(path, query, force_boolean = true)
click to toggle source
# File lib/memfs/file.rb, line 331 def self.stat_query(path, query, force_boolean = true) response = fs.find(path) && stat(path).public_send(query) force_boolean ? !!response : response end
Public Instance Methods
atime()
click to toggle source
# File lib/memfs/file.rb, line 263 def atime File.atime(path) end
chmod(mode_int)
click to toggle source
# File lib/memfs/file.rb, line 267 def chmod(mode_int) fs.chmod(mode_int, path) SUCCESS end
chown(uid, gid = nil)
click to toggle source
# File lib/memfs/file.rb, line 272 def chown(uid, gid = nil) fs.chown(uid, gid, path) SUCCESS end
ctime()
click to toggle source
# File lib/memfs/file.rb, line 277 def ctime File.ctime(path) end
flock(*)
click to toggle source
# File lib/memfs/file.rb, line 281 def flock(*) SUCCESS end
lstat()
click to toggle source
# File lib/memfs/file.rb, line 289 def lstat File.lstat(path) end
mtime()
click to toggle source
# File lib/memfs/file.rb, line 285 def mtime File.mtime(path) end
size()
click to toggle source
# File lib/memfs/file.rb, line 293 def size entry.size end
truncate(integer)
click to toggle source
# File lib/memfs/file.rb, line 297 def truncate(integer) File.truncate(path, integer) end