Class: Treebis::FileUtilsProxy
Constant Summary
Constants included
from Colorize
Colorize::Codes
Constants included
from Stylize
Stylize::ReasonStyles, Stylize::StyleCodes
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from Antecedent
#init_path_antecedent, #path_antecedent
Methods included from Capture3
#capture3
Methods included from Colorize
colorize
Methods included from Stylize
#get_style, #notice
Constructor Details
#initialize {|_self| ... } ⇒ FileUtilsProxy
Returns a new instance of FileUtilsProxy.
330
331
332
333
334
335
336
337
338
|
# File 'lib/treebis.rb', line 330
def initialize &block
@color = nil
@prefix = ''
@pretty = false
init_path_antecedent
@ui = Config.default_out_stream
@ui_stack = nil
yield(self) if block_given?
end
|
Instance Attribute Details
#prefix ⇒ Object
Returns the value of attribute prefix.
359
360
361
|
# File 'lib/treebis.rb', line 359
def prefix
@prefix
end
|
#ui ⇒ Object
416
417
418
|
# File 'lib/treebis.rb', line 416
def ui
@ui.kind_of?(Proc) ? @ui.call : @ui end
|
Instance Method Details
#color?(&block) ⇒ Boolean
339
340
341
342
343
344
345
|
# File 'lib/treebis.rb', line 339
def color? &block
if block_given?
@color = block
else
@color.call
end
end
|
#cp(*args) ⇒ Object
346
347
348
349
350
351
352
353
354
355
356
357
358
|
# File 'lib/treebis.rb', line 346
def cp *args
opts = args.last.kind_of?(Hash) ? args.last : {}
ret, out, err = nil, "", nil
keep = {:pretty_name_target => opts.delete(:pretty_name_target) }
if ! @pretty
ret = super(*args)
else
out, err, ret = capture3{ super(*args) }
opts.merge!(keep)
pretty_puts_cp out, err, ret, *args
end
ret
end
|
#mkdir_p(*args) ⇒ Object
402
403
404
405
406
407
408
409
410
411
412
413
|
# File 'lib/treebis.rb', line 402
def mkdir_p *args
ret, out, err = nil, "", nil
if File.exist?(args.first)
err = "treebis: mkdir_p: exists: #{args.first}"
elsif @pretty
out, err, ret = capture3{ super(*args) }
else
ret = super
end
pretty_puts_mkdir_p out, err, ret, *args
ret
end
|
#not_pretty! ⇒ Object
399
400
401
|
# File 'lib/treebis.rb', line 399
def not_pretty!
@pretty = false
end
|
#pretty! ⇒ Object
364
365
366
|
# File 'lib/treebis.rb', line 364
def pretty!
@pretty = true
end
|
#remove_entry_secure(path, force = false, opts = {}) ⇒ Object
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
|
# File 'lib/treebis.rb', line 367
def remove_entry_secure path, force=false, opts={}
opts = {:verbose=>true}.merge(opts)
did = nil
if File.exist?(path)
super(path, force)
did = true
err = "rm -rf #{path}"
colors = [:bright,:green]
else
did = false
err = "rm -rf (didn't exist:) #{path}"
colors = [:bright, :red]
end
if opts[:verbose]
if @pretty
err.sub!(/\Arm -rf/){colorize('rm -rf',*colors)}
err = "#{prefix}#{err}"
end
ui.puts err
end
did
end
|
#rm(*a) ⇒ Object
390
391
392
393
394
395
396
397
398
|
# File 'lib/treebis.rb', line 390
def rm *a
if @pretty
b = capture3{ super(*a) }
pretty_puts_rm(*(b+a))
else
ret = super(*a)
end
ret
end
|
#ui_pop ⇒ Object
427
428
429
430
431
432
|
# File 'lib/treebis.rb', line 427
def ui_pop
it = @ui
@ui = @ui_stack.pop
resp = it.kind_of?(StringIO) ? (it.rewind && it.read) : it
resp
end
|
#ui_push ⇒ Object
not sure about this, it breaks the otherwise faithful ‘api’ we don’t like it because of that, we do like it better than capture3 because we don’t need ugly hacks or tossing around globals
422
423
424
425
426
|
# File 'lib/treebis.rb', line 422
def ui_push
@ui_stack ||= []
@ui_stack.push @ui
@ui = StringIO.new
end
|