Class: BrewCaskTools::Tasks::Upgrade

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

Overview

Upgrade task

Instance Method Summary collapse

Methods inherited from Caskroom

#casks, #enumerate, #get

Constructor Details

#initialize(casks) ⇒ Upgrade

Returns a new instance of Upgrade.

Parameters:

  • optional

    casks [Array] array of cask names to upgrade



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

def initialize(casks)
  super()

  @upgrade = []

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

    @upgrade = compile
  else
    @upgrade = casks.map { |c| caskroom.get(c) }
    return say 'Invalid cask(s) specified', :red if @upgrade.compact.empty?
  end

  upgrade
end

Instance Method Details

#compileArray

Get list of casks to upgrade

Returns:

  • (Array)

    an array of casks to upgrade



31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/bct/tasks/upgrade.rb', line 31

def compile
  upgrade = []
  caskroom.enumerate do |cask|
    increment(cask)

    next unless cask.outdated?

    upgrade << cask
    progressbar.log "#{cask.info.name}: " \
    "#{cask.current} ==> #{cask.candidate}"
  end
  upgrade
end

#upgradeObject

Upgrade casks



46
47
48
49
50
51
52
# File 'lib/bct/tasks/upgrade.rb', line 46

def upgrade
  return say 'There are no casks to be upgraded', :green if @upgrade.empty?
  @upgrade.each(&:upgrade)

  # Cleanup casks that we upgraded
  Tasks::Cleanup.new(@upgrade.map(&:name))
end