Class: VirtualShell
Overview
Virtual Shell
c = VirtualShell.new
c.ls #=> ['ipso.txt']
Instance Attribute Summary collapse
-
#root ⇒ Object
readonly
Returns the value of attribute root.
Instance Method Summary collapse
-
#[](name) ⇒ Object
Direct access to a directory or a file.
-
#cd(dir, options = nil, &yld) ⇒ Object
(also: #chdir)
Change directory.
-
#chmod(mode, list, options = nil) ⇒ Object
chmod(mode, list, options).
-
#chmod_R(mode, list, options = nil) ⇒ Object
chmod_R(mode, list, options).
-
#chown(user, group, list, options = nil) ⇒ Object
chown(user, group, list, options).
-
#chown_R(user, group, list, options = nil) ⇒ Object
chown_R(user, group, list, options).
-
#cp(src, dest, options = nil) ⇒ Object
cp(src, dest, options) cp(list, dir, options).
-
#cp_r(src, dest, options = nil) ⇒ Object
cp_r(src, dest, options) cp_r(list, dir, options).
- #dryrun? ⇒ Boolean
-
#initialize(*root_and_options) ⇒ VirtualShell
constructor
A new instance of VirtualShell.
-
#install(src, dest, mode = src, options = nil) ⇒ Object
install(src, dest, mode = <src’s>, options).
-
#ln(old, new, options = nil) ⇒ Object
ln(old, new, options) ln(list, destdir, options).
-
#ln_s(old, new, options = nil) ⇒ Object
ln_s(old, new, options) ln_s(list, destdir, options).
-
#ln_sf(src, dest, options = nil) ⇒ Object
ln_sf(src, dest, options).
-
#ls(dir, options = nil) ⇒ Object
Directory listing.
-
#mkdir(dir, options = nil) ⇒ Object
mkdir(dir, options) mkdir(list, options).
-
#mkdir_p(dir, options = nil) ⇒ Object
mkdir_p(dir, options) mkdir_p(list, options).
-
#mv(src, dest, options = nil) ⇒ Object
(also: #move)
mv(src, dest, options) mv(list, dir, options).
-
#pwd ⇒ Object
Present working directory.
- #quiet? ⇒ Boolean
-
#rm(list, options = nil) ⇒ Object
rm(list, options).
-
#rm_r(list, options = nil) ⇒ Object
rm_r(list, options).
-
#rm_rf(list, options = nil) ⇒ Object
rm_rf(list, options).
-
#rmdir(dir, options = nil) ⇒ Object
rmdir(dir, options) rmdir(list, options).
-
#root?(dir = nil) ⇒ Boolean
Is a directory root?.
-
#touch(list, options = nil) ⇒ Object
touch(list, options).
- #verbose? ⇒ Boolean
Constructor Details
#initialize(*root_and_options) ⇒ VirtualShell
Returns a new instance of VirtualShell.
29 30 31 32 33 34 35 36 |
# File 'lib/more/facets/fileshell.rb', line 29 def initialize(*) @options = Hash === ? .pop : {} @root = .first || "/" @dryrun = [:dryrun] @quiet = [:quiet] #@force = options[:force] end |
Instance Attribute Details
Instance Method Details
#[](name) ⇒ Object
Direct access to a directory or a file.
44 45 46 47 48 49 50 51 52 |
# File 'lib/more/facets/fileshell.rb', line 44 def [](name) if File.directory?(name) Dir.new(name) elsif File.file?(name) File.new(name) else nil end end |
#cd(dir, options = nil, &yld) ⇒ Object Also known as: chdir
Change directory.
cd(dir, options) cd(dir, options) {|dir| .… }
76 77 78 |
# File 'lib/more/facets/fileshell.rb', line 76 def cd(dir, =nil, &yld) fu().cd(dir, &yld) end |
#chmod(mode, list, options = nil) ⇒ Object
chmod(mode, list, options)
156 157 158 |
# File 'lib/more/facets/fileshell.rb', line 156 def chmod(mode, list, =nil) fu().chmod(mode, list) end |
#chmod_R(mode, list, options = nil) ⇒ Object
chmod_R(mode, list, options)
161 162 163 |
# File 'lib/more/facets/fileshell.rb', line 161 def chmod_R(mode, list, =nil) fu().chmod_R(mode, list) end |
#chown(user, group, list, options = nil) ⇒ Object
chown(user, group, list, options)
166 167 168 |
# File 'lib/more/facets/fileshell.rb', line 166 def chown(user, group, list, =nil) fu().chown(user, group, list) end |
#chown_R(user, group, list, options = nil) ⇒ Object
chown_R(user, group, list, options)
171 172 173 |
# File 'lib/more/facets/fileshell.rb', line 171 def chown_R(user, group, list, =nil) fu().chown_R(user, group, list) end |
#cp(src, dest, options = nil) ⇒ Object
cp(src, dest, options) cp(list, dir, options)
118 119 120 |
# File 'lib/more/facets/fileshell.rb', line 118 def cp(src, dest, =nil) fu().cp(src, dest) end |
#cp_r(src, dest, options = nil) ⇒ Object
cp_r(src, dest, options) cp_r(list, dir, options)
124 125 126 |
# File 'lib/more/facets/fileshell.rb', line 124 def cp_r(src, dest, =nil) fu().cp_r(src, dest) end |
#dryrun? ⇒ Boolean
38 |
# File 'lib/more/facets/fileshell.rb', line 38 def dryrun? ; @dryrun ; end |
#install(src, dest, mode = src, options = nil) ⇒ Object
install(src, dest, mode = <src’s>, options)
151 152 153 |
# File 'lib/more/facets/fileshell.rb', line 151 def install(src, dest, mode=src, =nil) fu().install(src, dest, mode) end |
#ln(old, new, options = nil) ⇒ Object
ln(old, new, options) ln(list, destdir, options)
101 102 103 |
# File 'lib/more/facets/fileshell.rb', line 101 def ln(old, new, =nil) fu().ln(old, new) end |
#ln_s(old, new, options = nil) ⇒ Object
ln_s(old, new, options) ln_s(list, destdir, options)
107 108 109 |
# File 'lib/more/facets/fileshell.rb', line 107 def ln_s(old, new, =nil) fu().ln_s(old, new) end |
#ln_sf(src, dest, options = nil) ⇒ Object
ln_sf(src, dest, options)
112 113 114 |
# File 'lib/more/facets/fileshell.rb', line 112 def ln_sf(src, dest, =nil) fu().ln_sf(src, dest) end |
#ls(dir, options = nil) ⇒ Object
Directory listing
66 67 68 69 70 |
# File 'lib/more/facets/fileshell.rb', line 66 def ls(dir, =nil) Dir.entries.collect do |f| File.directory?(f) ? Dir.new(f) : File.new(f) end end |
#mkdir(dir, options = nil) ⇒ Object
mkdir(dir, options) mkdir(list, options)
83 84 85 |
# File 'lib/more/facets/fileshell.rb', line 83 def mkdir(dir, =nil) fu().mkdir(dir) end |
#mkdir_p(dir, options = nil) ⇒ Object
mkdir_p(dir, options) mkdir_p(list, options)
89 90 91 |
# File 'lib/more/facets/fileshell.rb', line 89 def mkdir_p(dir, =nil) fu().mkdir_p(dir) end |
#mv(src, dest, options = nil) ⇒ Object Also known as: move
mv(src, dest, options) mv(list, dir, options)
130 131 132 |
# File 'lib/more/facets/fileshell.rb', line 130 def mv(src, dest, =nil) fu().mv(src, dest) end |
#pwd ⇒ Object
Present working directory.
63 |
# File 'lib/more/facets/fileshell.rb', line 63 def pwd; super; end |
#quiet? ⇒ Boolean
39 |
# File 'lib/more/facets/fileshell.rb', line 39 def quiet? ; @quiet ; end |
#rm(list, options = nil) ⇒ Object
rm(list, options)
136 137 138 |
# File 'lib/more/facets/fileshell.rb', line 136 def rm(list, =nil) fu().rm(list) end |
#rm_r(list, options = nil) ⇒ Object
rm_r(list, options)
141 142 143 |
# File 'lib/more/facets/fileshell.rb', line 141 def rm_r(list, =nil) fu().rm_r(list) end |
#rm_rf(list, options = nil) ⇒ Object
rm_rf(list, options)
146 147 148 |
# File 'lib/more/facets/fileshell.rb', line 146 def rm_rf(list, =nil) fu().rm_rf(list) end |
#rmdir(dir, options = nil) ⇒ Object
rmdir(dir, options) rmdir(list, options)
95 96 97 |
# File 'lib/more/facets/fileshell.rb', line 95 def rmdir(dir, =nil) fu().rmdir(dir) end |
#root?(dir = nil) ⇒ Boolean
Is a directory root?
55 56 57 58 59 60 |
# File 'lib/more/facets/fileshell.rb', line 55 def root?(dir=nil) pth = File.(dir||work) return true if pth == '/' return true if pth =~ /^(\w:)?\/$/ false end |
#touch(list, options = nil) ⇒ Object
touch(list, options)
176 177 178 |
# File 'lib/more/facets/fileshell.rb', line 176 def touch(list, =nil) fu().touch(list) end |
#verbose? ⇒ Boolean
40 |
# File 'lib/more/facets/fileshell.rb', line 40 def verbose? ; !@quiet ; end |