Class: Path::Backend::Sys
- Inherits:
-
Object
- Object
- Path::Backend::Sys
- Defined in:
- lib/rubypath/backend/sys.rb
Overview
rubocop:disable ClassLength
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
- #getwd ⇒ Object
- #glob(pattern, flags = 0) ⇒ 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
- #touch(path) ⇒ Object
- #umask ⇒ Object
- #umask=(mask) ⇒ Object
- #unlink(path) ⇒ Object
- #ur(path) ⇒ Object
- #user ⇒ Object
- #write(path, content, *args) ⇒ Object
Constructor Details
Instance Method Details
#atime(path) ⇒ Object
104 105 106 |
# File 'lib/rubypath/backend/sys.rb', line 104 def atime(path) fs path, ::File, :atime, r(path) end |
#atime=(path, time) ⇒ Object
108 109 110 |
# 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) ⇒ Object
138 139 140 |
# File 'lib/rubypath/backend/sys.rb', line 138 def chmod(path, mode) fs path, ::File, :chmod, mode, r(path) end |
#directory?(path) ⇒ Boolean
76 77 78 |
# File 'lib/rubypath/backend/sys.rb', line 76 def directory?(path) fs path, ::File, :directory?, r(path) end |
#entries(path) ⇒ Object
112 113 114 |
# File 'lib/rubypath/backend/sys.rb', line 112 def entries(path) fs path, ::Dir, :entries, r(path) end |
#exists?(path) ⇒ Boolean
64 65 66 |
# File 'lib/rubypath/backend/sys.rb', line 64 def exists?(path) fs path, ::File, :exists?, r(path) end |
#expand_path(path, base) ⇒ Object
OPERATIONS
60 61 62 |
# File 'lib/rubypath/backend/sys.rb', line 60 def (path, base) ::File. path, base end |
#file?(path) ⇒ Boolean
80 81 82 |
# File 'lib/rubypath/backend/sys.rb', line 80 def file?(path) fs path, ::File, :file?, r(path) end |
#fs(path, obj, method, *args) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 |
# 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 ⇒ Object
20 21 22 |
# File 'lib/rubypath/backend/sys.rb', line 20 def getwd ::Dir.getwd end |
#glob(pattern, flags = 0) ⇒ Object
116 117 118 119 120 121 122 123 124 |
# 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) ⇒ Object
16 17 18 |
# File 'lib/rubypath/backend/sys.rb', line 16 def home(user) ::File. "~#{user}" end |
#mkdir(path) ⇒ Object
68 69 70 |
# File 'lib/rubypath/backend/sys.rb', line 68 def mkdir(path) fs path, ::Dir, :mkdir, r(path) end |
#mkpath(path) ⇒ Object
72 73 74 |
# File 'lib/rubypath/backend/sys.rb', line 72 def mkpath(path) fs path, ::FileUtils, :mkdir_p, r(path) end |
#mode(path) ⇒ Object
134 135 136 |
# File 'lib/rubypath/backend/sys.rb', line 134 def mode(path) fs(path, ::File, :stat, r(path)).mode & 0o777 end |
#mtime(path) ⇒ Object
96 97 98 |
# File 'lib/rubypath/backend/sys.rb', line 96 def mtime(path) fs path, ::File, :mtime, r(path) end |
#mtime=(path, time) ⇒ Object
100 101 102 |
# File 'lib/rubypath/backend/sys.rb', line 100 def mtime=(path, time) fs path, ::File, :utime, atime(path), time, r(path) end |
#quit ⇒ Object
12 13 14 |
# File 'lib/rubypath/backend/sys.rb', line 12 def quit File.umask @umask end |
#r(path) ⇒ Object
30 31 32 33 |
# File 'lib/rubypath/backend/sys.rb', line 30 def r(path) return path unless @root ::File.("#{@root}/#{::File.(path)}") end |
#read(path, *args) ⇒ Object
92 93 94 |
# File 'lib/rubypath/backend/sys.rb', line 92 def read(path, *args) fs path, ::IO, :read, r(path), *args end |
#rmtree(path) ⇒ Object
146 147 148 |
# File 'lib/rubypath/backend/sys.rb', line 146 def rmtree(path) fs path, ::FileUtils, :rm_r, r(path), force: true end |
#rmtree!(path) ⇒ Object
150 151 152 |
# File 'lib/rubypath/backend/sys.rb', line 150 def rmtree!(path) fs path, ::FileUtils, :rm_r, r(path) end |
#safe_rmtree(path) ⇒ Object
154 155 156 |
# 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) ⇒ Object
158 159 160 |
# File 'lib/rubypath/backend/sys.rb', line 158 def safe_rmtree!(path) fs path, ::FileUtils, :rm_r, r(path), secure: true end |
#touch(path) ⇒ Object
84 85 86 |
# File 'lib/rubypath/backend/sys.rb', line 84 def touch(path) fs path, ::FileUtils, :touch, r(path) end |
#umask ⇒ Object
126 127 128 |
# File 'lib/rubypath/backend/sys.rb', line 126 def umask File.umask end |
#umask=(mask) ⇒ Object
130 131 132 |
# File 'lib/rubypath/backend/sys.rb', line 130 def umask=(mask) File.umask mask end |
#unlink(path) ⇒ Object
142 143 144 |
# File 'lib/rubypath/backend/sys.rb', line 142 def unlink(path) fs path, ::File, :unlink, r(path) end |
#ur(path) ⇒ Object
35 36 37 38 39 40 41 42 43 |
# 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 ⇒ Object
24 25 26 27 28 |
# File 'lib/rubypath/backend/sys.rb', line 24 def user require 'etc' Etc.getlogin end |
#write(path, content, *args) ⇒ Object
88 89 90 |
# File 'lib/rubypath/backend/sys.rb', line 88 def write(path, content, *args) fs path, ::IO, :write, r(path), content, *args end |