Class: FileShell
- Defined in:
- lib/gems/facets-2.4.5/lib/more/facets/fileshell.rb
Overview
File Shell
Comprehensive file system access tool. FileShell acts as a “virtual” shell prompt.
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) ⇒ FileShell
constructor
A new instance of FileShell.
-
#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) ⇒ FileShell
Returns a new instance of FileShell.
33 34 35 36 37 38 39 40 |
# File 'lib/gems/facets-2.4.5/lib/more/facets/fileshell.rb', line 33 def initialize(*) = Hash === ? .pop : {} @root = .first || "/" @dryrun = [:dryrun] @quiet = [:quiet] #@force = options[:force] end |
Instance Attribute Details
#root ⇒ Object (readonly)
Returns the value of attribute root.
31 32 33 |
# File 'lib/gems/facets-2.4.5/lib/more/facets/fileshell.rb', line 31 def root @root end |
Instance Method Details
#[](name) ⇒ Object
Direct access to a directory or a file.
48 49 50 51 52 53 54 55 56 |
# File 'lib/gems/facets-2.4.5/lib/more/facets/fileshell.rb', line 48 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| .… }
80 81 82 |
# File 'lib/gems/facets-2.4.5/lib/more/facets/fileshell.rb', line 80 def cd(dir, =nil, &yld) fu().cd(dir, &yld) end |
#chmod(mode, list, options = nil) ⇒ Object
chmod(mode, list, options)
160 161 162 |
# File 'lib/gems/facets-2.4.5/lib/more/facets/fileshell.rb', line 160 def chmod(mode, list, =nil) fu().chmod(mode, list) end |
#chmod_R(mode, list, options = nil) ⇒ Object
chmod_R(mode, list, options)
165 166 167 |
# File 'lib/gems/facets-2.4.5/lib/more/facets/fileshell.rb', line 165 def chmod_R(mode, list, =nil) fu().chmod_R(mode, list) end |
#chown(user, group, list, options = nil) ⇒ Object
chown(user, group, list, options)
170 171 172 |
# File 'lib/gems/facets-2.4.5/lib/more/facets/fileshell.rb', line 170 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)
175 176 177 |
# File 'lib/gems/facets-2.4.5/lib/more/facets/fileshell.rb', line 175 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)
122 123 124 |
# File 'lib/gems/facets-2.4.5/lib/more/facets/fileshell.rb', line 122 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)
128 129 130 |
# File 'lib/gems/facets-2.4.5/lib/more/facets/fileshell.rb', line 128 def cp_r(src, dest, =nil) fu().cp_r(src, dest) end |
#dryrun? ⇒ Boolean
42 |
# File 'lib/gems/facets-2.4.5/lib/more/facets/fileshell.rb', line 42 def dryrun? ; @dryrun ; end |
#install(src, dest, mode = src, options = nil) ⇒ Object
install(src, dest, mode = <src’s>, options)
155 156 157 |
# File 'lib/gems/facets-2.4.5/lib/more/facets/fileshell.rb', line 155 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)
105 106 107 |
# File 'lib/gems/facets-2.4.5/lib/more/facets/fileshell.rb', line 105 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)
111 112 113 |
# File 'lib/gems/facets-2.4.5/lib/more/facets/fileshell.rb', line 111 def ln_s(old, new, =nil) fu().ln_s(old, new) end |
#ln_sf(src, dest, options = nil) ⇒ Object
ln_sf(src, dest, options)
116 117 118 |
# File 'lib/gems/facets-2.4.5/lib/more/facets/fileshell.rb', line 116 def ln_sf(src, dest, =nil) fu().ln_sf(src, dest) end |
#ls(dir, options = nil) ⇒ Object
Directory listing
70 71 72 73 74 |
# File 'lib/gems/facets-2.4.5/lib/more/facets/fileshell.rb', line 70 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)
87 88 89 |
# File 'lib/gems/facets-2.4.5/lib/more/facets/fileshell.rb', line 87 def mkdir(dir, =nil) fu().mkdir(dir) end |
#mkdir_p(dir, options = nil) ⇒ Object
mkdir_p(dir, options) mkdir_p(list, options)
93 94 95 |
# File 'lib/gems/facets-2.4.5/lib/more/facets/fileshell.rb', line 93 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)
134 135 136 |
# File 'lib/gems/facets-2.4.5/lib/more/facets/fileshell.rb', line 134 def mv(src, dest, =nil) fu().mv(src, dest) end |
#pwd ⇒ Object
Present working directory.
67 |
# File 'lib/gems/facets-2.4.5/lib/more/facets/fileshell.rb', line 67 def pwd; super; end |
#quiet? ⇒ Boolean
43 |
# File 'lib/gems/facets-2.4.5/lib/more/facets/fileshell.rb', line 43 def quiet? ; @quiet ; end |
#rm(list, options = nil) ⇒ Object
rm(list, options)
140 141 142 |
# File 'lib/gems/facets-2.4.5/lib/more/facets/fileshell.rb', line 140 def rm(list, =nil) fu().rm(list) end |
#rm_r(list, options = nil) ⇒ Object
rm_r(list, options)
145 146 147 |
# File 'lib/gems/facets-2.4.5/lib/more/facets/fileshell.rb', line 145 def rm_r(list, =nil) fu().rm_r(list) end |
#rm_rf(list, options = nil) ⇒ Object
rm_rf(list, options)
150 151 152 |
# File 'lib/gems/facets-2.4.5/lib/more/facets/fileshell.rb', line 150 def rm_rf(list, =nil) fu().rm_rf(list) end |
#rmdir(dir, options = nil) ⇒ Object
rmdir(dir, options) rmdir(list, options)
99 100 101 |
# File 'lib/gems/facets-2.4.5/lib/more/facets/fileshell.rb', line 99 def rmdir(dir, =nil) fu().rmdir(dir) end |
#root?(dir = nil) ⇒ Boolean
Is a directory root?
59 60 61 62 63 64 |
# File 'lib/gems/facets-2.4.5/lib/more/facets/fileshell.rb', line 59 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)
180 181 182 |
# File 'lib/gems/facets-2.4.5/lib/more/facets/fileshell.rb', line 180 def touch(list, =nil) fu().touch(list) end |
#verbose? ⇒ Boolean
44 |
# File 'lib/gems/facets-2.4.5/lib/more/facets/fileshell.rb', line 44 def verbose? ; !@quiet ; end |