Class: FileShell

Inherits:
Object show all
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

Instance Method Summary collapse

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(*root_and_options)
  @options = Hash === root_and_options ? root_and_options.pop : {}
  @root    = root_and_options.first || "/"

  @dryrun = options[:dryrun]
  @quiet  = options[:quiet]
  #@force  = options[:force]
end

Instance Attribute Details

#rootObject (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, options=nil, &yld)
  fu(options).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, options=nil)
  fu(options).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, options=nil)
  fu(options).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, options=nil)
  fu(options).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, options=nil)
  fu(options).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, options=nil)
  fu(options).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, options=nil)
  fu(options).cp_r(src, dest)
end

#dryrun?Boolean

Returns:

  • (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, options=nil)
  fu(options).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, options=nil)
  fu(options).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, options=nil)
  fu(options).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, options=nil)
  fu(options).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, options=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, options=nil)
  fu(options).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, options=nil)
  fu(options).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, options=nil)
  fu(options).mv(src, dest)
end

#pwdObject

Present working directory.



67
# File 'lib/gems/facets-2.4.5/lib/more/facets/fileshell.rb', line 67

def pwd; super; end

#quiet?Boolean

Returns:

  • (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, options=nil)
  fu(options).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, options=nil)
  fu(options).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, options=nil)
  fu(options).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, options=nil)
  fu(options).rmdir(dir)
end

#root?(dir = nil) ⇒ Boolean

Is a directory root?

Returns:

  • (Boolean)


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.expand_path(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, options=nil)
  fu(options).touch(list)
end

#verbose?Boolean

Returns:

  • (Boolean)


44
# File 'lib/gems/facets-2.4.5/lib/more/facets/fileshell.rb', line 44

def verbose?  ; !@quiet  ; end