Class: Infect::Cleanup
- Inherits:
-
Object
- Object
- Infect::Cleanup
- Includes:
- Colorize
- Defined in:
- lib/infect/cleanup.rb
Instance Attribute Summary collapse
-
#force ⇒ Object
readonly
Returns the value of attribute force.
-
#names ⇒ Object
readonly
Returns the value of attribute names.
Instance Method Summary collapse
- #call ⇒ Object
- #confirm(name) ⇒ Object
-
#initialize(list, args) ⇒ Cleanup
constructor
A new instance of Cleanup.
Methods included from Colorize
Constructor Details
#initialize(list, args) ⇒ Cleanup
Returns a new instance of Cleanup.
6 7 8 9 |
# File 'lib/infect/cleanup.rb', line 6 def initialize(list, args) @names = list.map{|p| File.basename(p)} @force = args[:force] || false end |
Instance Attribute Details
#force ⇒ Object (readonly)
Returns the value of attribute force.
4 5 6 |
# File 'lib/infect/cleanup.rb', line 4 def force @force end |
#names ⇒ Object (readonly)
Returns the value of attribute names.
4 5 6 |
# File 'lib/infect/cleanup.rb', line 4 def names @names end |
Instance Method Details
#call ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/infect/cleanup.rb', line 11 def call Dir["#{PACK_DIR}*/*/*"].each do |path| unless names.include? File.basename(path) if confirm(path) notice "Deleting #{path}" require 'fileutils' FileUtils.rm_rf path else notice "Leaving #{path}" end end end end |
#confirm(name) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/infect/cleanup.rb', line 25 def confirm(name) unless force print "Remove #{name}? [Yn]: " response = STDIN.gets.chomp case response.downcase when '' true when 'y' true else false end end end |