Class: Path::Backend::Sys
- Inherits:
-
Object
- Object
- Path::Backend::Sys
- Defined in:
- lib/rubypath/backend/sys.rb
Instance Method Summary collapse
- #atime(path) ⇒ Object
- #atime=(path, time) ⇒ Object
- #chmod(path, mode) ⇒ Object
- #directory?(path) ⇒ Boolean
- #entries(path) ⇒ Object
- #exists?(path) ⇒ Boolean
-
#expand_path(path, base) ⇒ Object
OPERATIONS.
- #file?(path) ⇒ Boolean
- #fs(path, obj, method, *args) ⇒ Object
- #get_umask ⇒ Object
- #getwd ⇒ Object
- #glob(pattern, flags = 0, &block) ⇒ Object
- #home(user) ⇒ Object
-
#initialize(root = nil) ⇒ Sys
constructor
A new instance of Sys.
- #mkdir(path) ⇒ Object
- #mkpath(path) ⇒ Object
- #mode(path) ⇒ Object
- #mtime(path) ⇒ Object
- #mtime=(path, time) ⇒ Object
- #quit ⇒ Object
- #r(path) ⇒ Object
- #read(path, *args) ⇒ Object
- #rmtree(path) ⇒ Object
- #rmtree!(path) ⇒ Object
- #safe_rmtree(path) ⇒ Object
- #safe_rmtree!(path) ⇒ Object
- #set_umask(mask) ⇒ Object
- #touch(path) ⇒ Object
- #unlink(path) ⇒ Object
- #ur(path) ⇒ Object
- #user ⇒ Object
- #write(path, content, *args) ⇒ Object
Constructor Details
Instance Method Details
#atime(path) ⇒ Object
103 104 105 |
# File 'lib/rubypath/backend/sys.rb', line 103 def atime(path) fs path, ::File, :atime, r(path) end |
#atime=(path, time) ⇒ Object
107 108 109 |
# File 'lib/rubypath/backend/sys.rb', line 107 def atime=(path, time) fs path, ::File, :utime, time, mtime(path), r(path) end |
#chmod(path, mode) ⇒ Object
137 138 139 |
# File 'lib/rubypath/backend/sys.rb', line 137 def chmod(path, mode) fs path, ::File, :chmod, mode, r(path) end |
#directory?(path) ⇒ Boolean
75 76 77 |
# File 'lib/rubypath/backend/sys.rb', line 75 def directory?(path) fs path, ::File, :directory?, r(path) end |
#entries(path) ⇒ Object
111 112 113 |
# File 'lib/rubypath/backend/sys.rb', line 111 def entries(path) fs path, ::Dir, :entries, r(path) end |
#exists?(path) ⇒ Boolean
63 64 65 |
# File 'lib/rubypath/backend/sys.rb', line 63 def exists?(path) fs path, ::File, :exists?, r(path) end |
#expand_path(path, base) ⇒ Object
OPERATIONS
59 60 61 |
# File 'lib/rubypath/backend/sys.rb', line 59 def (path, base) ::File. path, base end |
#file?(path) ⇒ Boolean
79 80 81 |
# File 'lib/rubypath/backend/sys.rb', line 79 def file?(path) fs path, ::File, :file?, r(path) end |
#fs(path, obj, method, *args) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/rubypath/backend/sys.rb', line 44 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 |
#get_umask ⇒ Object
125 126 127 |
# File 'lib/rubypath/backend/sys.rb', line 125 def get_umask File.umask end |
#getwd ⇒ Object
19 20 21 |
# File 'lib/rubypath/backend/sys.rb', line 19 def getwd ::Dir.getwd end |
#glob(pattern, flags = 0, &block) ⇒ Object
115 116 117 118 119 120 121 122 123 |
# File 'lib/rubypath/backend/sys.rb', line 115 def glob(pattern, flags = 0, &block) 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) ⇒ Object
15 16 17 |
# File 'lib/rubypath/backend/sys.rb', line 15 def home(user) ::File. "~#{user}" end |
#mkdir(path) ⇒ Object
67 68 69 |
# File 'lib/rubypath/backend/sys.rb', line 67 def mkdir(path) fs path, ::Dir, :mkdir, r(path) end |
#mkpath(path) ⇒ Object
71 72 73 |
# File 'lib/rubypath/backend/sys.rb', line 71 def mkpath(path) fs path, ::FileUtils, :mkdir_p, r(path) end |
#mode(path) ⇒ Object
133 134 135 |
# File 'lib/rubypath/backend/sys.rb', line 133 def mode(path) fs(path, ::File, :stat, r(path)).mode & 0777 end |
#mtime(path) ⇒ Object
95 96 97 |
# File 'lib/rubypath/backend/sys.rb', line 95 def mtime(path) fs path, ::File, :mtime, r(path) end |
#mtime=(path, time) ⇒ Object
99 100 101 |
# File 'lib/rubypath/backend/sys.rb', line 99 def mtime=(path, time) fs path, ::File, :utime, atime(path), time, r(path) end |
#quit ⇒ Object
11 12 13 |
# File 'lib/rubypath/backend/sys.rb', line 11 def quit File.umask @umask end |
#r(path) ⇒ Object
29 30 31 32 |
# File 'lib/rubypath/backend/sys.rb', line 29 def r(path) return path unless @root ::File.("#{@root}/#{::File.(path)}") end |
#read(path, *args) ⇒ Object
91 92 93 |
# File 'lib/rubypath/backend/sys.rb', line 91 def read(path, *args) fs path, ::IO, :read, r(path), *args end |
#rmtree(path) ⇒ Object
145 146 147 |
# File 'lib/rubypath/backend/sys.rb', line 145 def rmtree(path) fs path, ::FileUtils, :rm_r, r(path), force: true end |
#rmtree!(path) ⇒ Object
149 150 151 |
# File 'lib/rubypath/backend/sys.rb', line 149 def rmtree!(path) fs path, ::FileUtils, :rm_r, r(path) end |
#safe_rmtree(path) ⇒ Object
153 154 155 |
# File 'lib/rubypath/backend/sys.rb', line 153 def safe_rmtree(path) fs path, ::FileUtils, :rm_r, r(path), force: true, secure: true end |
#safe_rmtree!(path) ⇒ Object
157 158 159 |
# File 'lib/rubypath/backend/sys.rb', line 157 def safe_rmtree!(path) fs path, ::FileUtils, :rm_r, r(path), secure: true end |
#set_umask(mask) ⇒ Object
129 130 131 |
# File 'lib/rubypath/backend/sys.rb', line 129 def set_umask(mask) File.umask mask end |
#touch(path) ⇒ Object
83 84 85 |
# File 'lib/rubypath/backend/sys.rb', line 83 def touch(path) fs path, ::FileUtils, :touch, r(path) end |
#unlink(path) ⇒ Object
141 142 143 |
# File 'lib/rubypath/backend/sys.rb', line 141 def unlink(path) fs path, ::File, :unlink, r(path) end |
#ur(path) ⇒ Object
34 35 36 37 38 39 40 41 42 |
# File 'lib/rubypath/backend/sys.rb', line 34 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 ⇒ Object
23 24 25 26 27 |
# File 'lib/rubypath/backend/sys.rb', line 23 def user require 'etc' Etc.getlogin end |
#write(path, content, *args) ⇒ Object
87 88 89 |
# File 'lib/rubypath/backend/sys.rb', line 87 def write(path, content, *args) fs path, ::IO, :write, r(path), content, *args end |