Class: VirtualShell

Inherits:
Object show all
Defined in:
lib/more/facets/fileshell.rb

Overview

Virtual Shell

c = VirtualShell.new
c.ls  #=> ['ipso.txt']

Instance Attribute Summary collapse

Instance Method Summary collapse

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(*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.



27
28
29
# File 'lib/more/facets/fileshell.rb', line 27

def root
  @root
end

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, options=nil, &yld)
  fu(options).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, options=nil)
  fu(options).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, options=nil)
  fu(options).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, options=nil)
  fu(options).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, options=nil)
  fu(options).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, 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)



124
125
126
# File 'lib/more/facets/fileshell.rb', line 124

def cp_r(src, dest, options=nil)
  fu(options).cp_r(src, dest)
end

#dryrun?Boolean

Returns:

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



107
108
109
# File 'lib/more/facets/fileshell.rb', line 107

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)



112
113
114
# File 'lib/more/facets/fileshell.rb', line 112

def ln_sf(src, dest, options=nil)
  fu(options).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, 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)



83
84
85
# File 'lib/more/facets/fileshell.rb', line 83

def mkdir(dir, options=nil)
  fu(options).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, 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)



130
131
132
# File 'lib/more/facets/fileshell.rb', line 130

def mv(src, dest, options=nil)
  fu(options).mv(src, dest)
end

#pwdObject

Present working directory.



63
# File 'lib/more/facets/fileshell.rb', line 63

def pwd; super; end

#quiet?Boolean

Returns:

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

#root?(dir = nil) ⇒ Boolean

Is a directory root?

Returns:

  • (Boolean)


55
56
57
58
59
60
# File 'lib/more/facets/fileshell.rb', line 55

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)



176
177
178
# File 'lib/more/facets/fileshell.rb', line 176

def touch(list, options=nil)
  fu(options).touch(list)
end

#verbose?Boolean

Returns:

  • (Boolean)


40
# File 'lib/more/facets/fileshell.rb', line 40

def verbose?  ; !@quiet  ; end