Class: BrewCaskTools::Tasks::Cleanup

Inherits:
Caskroom
  • Object
show all
Defined in:
lib/bct/tasks/cleanup.rb

Overview

Cleanup tasks

Instance Method Summary collapse

Methods inherited from Caskroom

#casklist, #casks, #enumerate, #get

Constructor Details

#initialize(cask_name) ⇒ Cleanup

Returns a new instance of Cleanup.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/bct/tasks/cleanup.rb', line 10

def initialize(cask_name)
  super()

  if cask_name.nil?
    progressbar.total = caskroom.casks.length
    progressbar.log "\nLooking for outdated casks..."

    return clean_all # Clean all casks
  end

  cask = caskroom.get(cask_name)
  return say 'Invalid cask specified', :red if cask.nil?

  clean_one(cask)
end

Instance Method Details

#clean_allObject



33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/bct/tasks/cleanup.rb', line 33

def clean_all
  cleaned_casks = []

  caskroom.enumerate do |cask|
    progressbar.title = "  #{cask.name.capitalize} "
    progressbar.increment

    cleaned_casks << cask if cask.can_cleanup?
  end

  return say "\nNo cleanup operations are necessary", :green if cleaned_casks.empty?

  cleaned_casks.each { |c| c.cleanup(&clean_block) }
end

#clean_blockObject



48
49
50
51
52
53
54
55
56
57
58
# File 'lib/bct/tasks/cleanup.rb', line 48

def clean_block
  proc do |c, versions|
    say "Cleaning up #{c.name}", :yellow
    dep_q = "#{c.name} has been deprecated. Ok to remove all versions?"
    if c.deprecated? && no?(dep_q, :red)
      say 'No action taken.', :red
      next
    end
    say "Removed #{versions.length} old version(s)", :yellow
  end
end

#clean_one(cask) ⇒ Object



26
27
28
29
30
31
# File 'lib/bct/tasks/cleanup.rb', line 26

def clean_one(cask)
  return say "#{cask.name.capitalize} does not have any outdated " \
    'versions. No cleanup operations are necessary', :green unless cask.can_cleanup?

  cask.cleanup(&clean_block)
end