class Path::Backend::Sys
rubocop:disable ClassLength
Public Class Methods
new(root = nil)
click to toggle source
# File lib/rubypath/backend/sys.rb, line 7 def initialize(root = nil) @root = ::File.expand_path root if root @umask = File.umask end
Public Instance Methods
atime(path)
click to toggle source
# File lib/rubypath/backend/sys.rb, line 104 def atime(path) fs path, ::File, :atime, r(path) end
atime=(path, time)
click to toggle source
# File lib/rubypath/backend/sys.rb, line 108 def atime=(path, time) fs path, ::File, :utime, time, mtime(path), r(path) end
chmod(path, mode)
click to toggle source
# File lib/rubypath/backend/sys.rb, line 138 def chmod(path, mode) fs path, ::File, :chmod, mode, r(path) end
directory?(path)
click to toggle source
# File lib/rubypath/backend/sys.rb, line 76 def directory?(path) fs path, ::File, :directory?, r(path) end
entries(path)
click to toggle source
# File lib/rubypath/backend/sys.rb, line 112 def entries(path) fs path, ::Dir, :entries, r(path) end
exists?(path)
click to toggle source
# File lib/rubypath/backend/sys.rb, line 64 def exists?(path) fs path, ::File, :exists?, r(path) end
expand_path(path, base)
click to toggle source
OPERATIONS
# File lib/rubypath/backend/sys.rb, line 60 def expand_path(path, base) ::File.expand_path path, base end
file?(path)
click to toggle source
# File lib/rubypath/backend/sys.rb, line 80 def file?(path) fs path, ::File, :file?, r(path) end
fs(path, obj, method, *args)
click to toggle source
# File lib/rubypath/backend/sys.rb, line 45 def fs(path, obj, method, *args) # puts "[FS] #{obj} #{method} #{args.inspect}" obj.send method, *args rescue Errno::ENOENT raise Errno::ENOENT.new path rescue Errno::EISDIR raise Errno::EISDIR.new path rescue Errno::ENOTDIR raise Errno::ENOTDIR.new path rescue Errno::EACCES raise Errno::EACCES.new path end
getwd()
click to toggle source
# File lib/rubypath/backend/sys.rb, line 20 def getwd ::Dir.getwd end
glob(pattern, flags = 0) { |ur(path)| ... }
click to toggle source
# File lib/rubypath/backend/sys.rb, line 116 def glob(pattern, flags = 0) if block_given? fs pattern, ::Dir, :glob, r(pattern), flags do |path| yield ur(path) end else fs(pattern, ::Dir, :glob, r(pattern), flags).map {|path| ur path } end end
home(user)
click to toggle source
# File lib/rubypath/backend/sys.rb, line 16 def home(user) ::File.expand_path "~#{user}" end
mkdir(path)
click to toggle source
# File lib/rubypath/backend/sys.rb, line 68 def mkdir(path) fs path, ::Dir, :mkdir, r(path) end
mkpath(path)
click to toggle source
# File lib/rubypath/backend/sys.rb, line 72 def mkpath(path) fs path, ::FileUtils, :mkdir_p, r(path) end
mode(path)
click to toggle source
# File lib/rubypath/backend/sys.rb, line 134 def mode(path) fs(path, ::File, :stat, r(path)).mode & 0o777 end
mtime(path)
click to toggle source
# File lib/rubypath/backend/sys.rb, line 96 def mtime(path) fs path, ::File, :mtime, r(path) end
mtime=(path, time)
click to toggle source
# File lib/rubypath/backend/sys.rb, line 100 def mtime=(path, time) fs path, ::File, :utime, atime(path), time, r(path) end
quit()
click to toggle source
# File lib/rubypath/backend/sys.rb, line 12 def quit File.umask @umask end
r(path)
click to toggle source
# File lib/rubypath/backend/sys.rb, line 30 def r(path) return path unless @root ::File.expand_path("#{@root}/#{::File.expand_path(path)}") end
read(path, *args)
click to toggle source
# File lib/rubypath/backend/sys.rb, line 92 def read(path, *args) fs path, ::IO, :read, r(path), *args end
rmtree(path)
click to toggle source
# File lib/rubypath/backend/sys.rb, line 146 def rmtree(path) fs path, ::FileUtils, :rm_r, r(path), force: true end
rmtree!(path)
click to toggle source
# File lib/rubypath/backend/sys.rb, line 150 def rmtree!(path) fs path, ::FileUtils, :rm_r, r(path) end
safe_rmtree(path)
click to toggle source
# File lib/rubypath/backend/sys.rb, line 154 def safe_rmtree(path) fs path, ::FileUtils, :rm_r, r(path), force: true, secure: true end
safe_rmtree!(path)
click to toggle source
# File lib/rubypath/backend/sys.rb, line 158 def safe_rmtree!(path) fs path, ::FileUtils, :rm_r, r(path), secure: true end
touch(path)
click to toggle source
# File lib/rubypath/backend/sys.rb, line 84 def touch(path) fs path, ::FileUtils, :touch, r(path) end
umask()
click to toggle source
# File lib/rubypath/backend/sys.rb, line 126 def umask File.umask end
umask=(mask)
click to toggle source
# File lib/rubypath/backend/sys.rb, line 130 def umask=(mask) File.umask mask end
unlink(path)
click to toggle source
# File lib/rubypath/backend/sys.rb, line 142 def unlink(path) fs path, ::File, :unlink, r(path) end
ur(path)
click to toggle source
# File lib/rubypath/backend/sys.rb, line 35 def ur(path) return path unless @root if path.slice(0, @root.length) == @root path.slice(@root.length, path.length - @root.length) else path end end
user()
click to toggle source
# File lib/rubypath/backend/sys.rb, line 24 def user require 'etc' Etc.getlogin end
write(path, content, *args)
click to toggle source
# File lib/rubypath/backend/sys.rb, line 88 def write(path, content, *args) fs path, ::IO, :write, r(path), content, *args end