Class: Infect::Cleanup

Inherits:
Object
  • Object
show all
Includes:
Colorize
Defined in:
lib/infect/cleanup.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Colorize

#colorize, #error, #notice

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

#forceObject (readonly)

Returns the value of attribute force.



4
5
6
# File 'lib/infect/cleanup.rb', line 4

def force
  @force
end

#namesObject (readonly)

Returns the value of attribute names.



4
5
6
# File 'lib/infect/cleanup.rb', line 4

def names
  @names
end

Instance Method Details

#callObject



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