Class: Folio::Prompt
- Inherits:
-
Object
- Object
- Folio::Prompt
- Defined in:
- lib/folio/prompt.rb
Overview
Prompt class
Instance Attribute Summary collapse
-
#work ⇒ Object
readonly
as a Directory object.
Class Method Summary collapse
Instance Method Summary collapse
-
#+(fname) ⇒ Object
(also: #/)
Join paths.
- #cd(dir, &block) ⇒ Object
- #chmod(mode, list, options) ⇒ Object
- #chmod_r(mode, list, options) ⇒ Object
-
#chown(user, group, list, options) ⇒ Object
alias_method :chmod_R, :chmod_r.
- #chown_r(user, group, list, options) ⇒ Object
-
#cp(src, dest, options) ⇒ Object
cp(list, dir, options).
-
#cp_r(src, dest, options) ⇒ Object
cp_r(list, dir, options).
-
#directories ⇒ Object
Returns Enumerator of documents.
-
#directory_entries ⇒ Object
Lists directory entries.
-
#document_entries ⇒ Object
Lists directory entries.
-
#documents ⇒ Object
Returns Enumerator of directories.
-
#entries ⇒ Object
(also: #ls)
Lists all entries.
-
#file(name) ⇒ Object
(also: #[])
Get the FileObject for the given file name.
-
#files ⇒ Object
Returns Enumerator of files objects.
-
#glob(*patterns) ⇒ Object
Glob pattern.
-
#initialize(*path) ⇒ Prompt
constructor
A new instance of Prompt.
- #install(src, dest, mode, options) ⇒ Object
-
#ln(old, new, options) ⇒ Object
ln(list, destdir, options).
-
#ln_s(old, new, options) ⇒ Object
ln_s(list, destdir, options).
- #ln_sf(old, new, options) ⇒ Object
-
#mkdir(dir, options) ⇒ Object
– fileutils ++.
- #mkdir_p(dir, options) ⇒ Object
-
#mode(opts = nil) ⇒ Object
Opertaton mode.
-
#mv(src, dest, options) ⇒ Object
mv(list, dir, options).
- #rm(list, options) ⇒ Object
- #rm_r(list, options) ⇒ Object
- #rm_rf(list, options) ⇒ Object
- #rmdir(dir, options) ⇒ Object
- #to_s ⇒ Object
-
#touch(list, options) ⇒ Object
alias_method :chown_R, :chown_r.
Constructor Details
#initialize(*path) ⇒ Prompt
Returns a new instance of Prompt.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/folio/prompt.rb', line 20 def initialize(*path) opts = (Hash===path.last ? path.pop : {}) mode(opts) if path.empty? path = Dir.pwd else path = File.join(*path) end raise FileNotFound unless ::File.exist?(path) raise FileNotFound unless ::File.directory?(path) @path = Directory.new(path) end |
Instance Attribute Details
#work ⇒ Object (readonly)
as a Directory object.
17 18 19 |
# File 'lib/folio/prompt.rb', line 17 def work @work end |
Class Method Details
.[](path) ⇒ Object
244 245 246 |
# File 'lib/folio/prompt.rb', line 244 def self.[](path) new(path) end |
Instance Method Details
#+(fname) ⇒ Object Also known as: /
Join paths.
62 63 64 |
# File 'lib/folio/prompt.rb', line 62 def +(fname) @work =+ fname end |
#cd(dir, &block) ⇒ Object
99 100 101 102 103 104 105 106 |
# File 'lib/folio/prompt.rb', line 99 def cd(dir, &block) #dir = localize(dir) if block @work.cd(dir, &block) else @work += dir end end |
#chmod(mode, list, options) ⇒ Object
189 190 191 192 |
# File 'lib/folio/prompt.rb', line 189 def chmod(mode, list, ) list = localize(list) fileutils.chmod(mode, list, ) end |
#chmod_r(mode, list, options) ⇒ Object
194 195 196 197 |
# File 'lib/folio/prompt.rb', line 194 def chmod_r(mode, list, ) list = localize(list) fileutils.chmod_r(mode, list, ) end |
#chown(user, group, list, options) ⇒ Object
alias_method :chmod_R, :chmod_r
200 201 202 203 |
# File 'lib/folio/prompt.rb', line 200 def chown(user, group, list, ) list = localize(list) fileutils.chown(user, group, list, ) end |
#chown_r(user, group, list, options) ⇒ Object
205 206 207 208 |
# File 'lib/folio/prompt.rb', line 205 def chown_r(user, group, list, ) list = localize(list) fileutils.chown_r(user, group, list, ) end |
#cp(src, dest, options) ⇒ Object
cp(list, dir, options)
148 149 150 151 152 |
# File 'lib/folio/prompt.rb', line 148 def cp(src, dest, ) src = localize(src) dest = localize(dest) fileutils.cp(src, dest, ) end |
#cp_r(src, dest, options) ⇒ Object
cp_r(list, dir, options)
155 156 157 158 159 |
# File 'lib/folio/prompt.rb', line 155 def cp_r(src, dest, ) src = localize(src) dest = localize(dest) fileutils.cp_r(src, dest, ) end |
#directories ⇒ Object
Returns Enumerator of documents.
90 |
# File 'lib/folio/prompt.rb', line 90 def directories ; work.directories ; end |
#directory_entries ⇒ Object
Lists directory entries.
74 75 76 |
# File 'lib/folio/prompt.rb', line 74 def directory_entries work.directory_entries end |
#document_entries ⇒ Object
Lists directory entries.
79 80 81 |
# File 'lib/folio/prompt.rb', line 79 def document_entries work.document_entries end |
#documents ⇒ Object
Returns Enumerator of directories.
87 |
# File 'lib/folio/prompt.rb', line 87 def documents ; work.documents ; end |
#entries ⇒ Object Also known as: ls
Lists all entries.
68 69 70 |
# File 'lib/folio/prompt.rb', line 68 def entries work.entries end |
#file(name) ⇒ Object Also known as: []
Get the FileObject for the given file name.
56 57 58 |
# File 'lib/folio/prompt.rb', line 56 def file(name) FileObject(name) end |
#files ⇒ Object
Returns Enumerator of files objects.
84 |
# File 'lib/folio/prompt.rb', line 84 def files ; work.files ; end |
#glob(*patterns) ⇒ Object
Glob pattern.
93 94 95 96 97 |
# File 'lib/folio/prompt.rb', line 93 def glob(*patterns) opts = (::Integer===patterns.last ? patterns.pop : 0) pattern = localize(pattern) ::Dir.glob(pattern, opts).each{ |f| FileObject[f] } end |
#install(src, dest, mode, options) ⇒ Object
183 184 185 186 187 |
# File 'lib/folio/prompt.rb', line 183 def install(src, dest, mode, ) src = localize(src) dest = localize(dest) fileutils.install(src, dest, mode, ) end |
#ln(old, new, options) ⇒ Object
ln(list, destdir, options)
128 129 130 131 132 |
# File 'lib/folio/prompt.rb', line 128 def ln(old, new, ) old = localize(old) new = localize(new) fileutils.ln(old, new, ) end |
#ln_s(old, new, options) ⇒ Object
ln_s(list, destdir, options)
135 136 137 138 139 |
# File 'lib/folio/prompt.rb', line 135 def ln_s(old, new, ) old = localize(old) new = localize(new) fileutils.ln_s(old, new, ) end |
#ln_sf(old, new, options) ⇒ Object
141 142 143 144 145 |
# File 'lib/folio/prompt.rb', line 141 def ln_sf(old, new, ) old = localize(old) new = localize(new) fileutils.ln_sf(old, new, ) end |
#mkdir(dir, options) ⇒ Object
– fileutils ++
112 113 114 115 |
# File 'lib/folio/prompt.rb', line 112 def mkdir(dir, ) dir = localize(dir) fileutils.mkdir(dir, ) end |
#mkdir_p(dir, options) ⇒ Object
117 118 119 120 |
# File 'lib/folio/prompt.rb', line 117 def mkdir_p(dir, ) dir = localize(dir) fileutils.mkdir_p(dir, ) end |
#mode(opts = nil) ⇒ Object
Opertaton mode. This can be :noop, :verbose or :dryrun. The later is the same as the first two combined.
38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/folio/prompt.rb', line 38 def mode(opts=nil) return @mode unless opts opts.each do |key, val| next unless val case key when :noop @mode = (@mode == :verbose ? :dryrun : :noop) when :verbose @mode = (@mode == :noop ? :dryrun : :verbose) when :dryrun @mode = :dryrun end end end |
#mv(src, dest, options) ⇒ Object
mv(list, dir, options)
162 163 164 165 166 |
# File 'lib/folio/prompt.rb', line 162 def mv(src, dest, ) src = localize(src) dest = localize(dest) fileutils.mv(src, dest, ) end |
#rm(list, options) ⇒ Object
168 169 170 171 |
# File 'lib/folio/prompt.rb', line 168 def rm(list, ) list = localize(list) fileutils.rm(list, ) end |
#rm_r(list, options) ⇒ Object
173 174 175 176 |
# File 'lib/folio/prompt.rb', line 173 def rm_r(list, ) list = localize(list) fileutils.rm_f(list, ) end |
#rm_rf(list, options) ⇒ Object
178 179 180 181 |
# File 'lib/folio/prompt.rb', line 178 def rm_rf(list, ) list = localize(list) fileutils.rm_rf(list, ) end |
#rmdir(dir, options) ⇒ Object
122 123 124 125 |
# File 'lib/folio/prompt.rb', line 122 def rmdir(dir, ) dir = localize(dir) fileutils.rmdir(dir, ) end |
#to_s ⇒ Object
53 |
# File 'lib/folio/prompt.rb', line 53 def to_s ; work.to_s ; end |
#touch(list, options) ⇒ Object
alias_method :chown_R, :chown_r
211 212 213 214 |
# File 'lib/folio/prompt.rb', line 211 def touch(list, ) list = localize(list) fileutils.touch(list, ) end |