Class: BrewCaskTools::Tasks::Outdated

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

Overview

Outdated cask tasks

Instance Method Summary collapse

Methods inherited from Caskroom

#caskroom, #progressbar

Constructor Details

#initializeOutdated

Returns a new instance of Outdated.



7
8
9
10
11
12
13
14
15
# File 'lib/bct/tasks/outdated.rb', line 7

def initialize
  super
  progressbar.total = caskroom.casks.length
  progressbar.log "\nLooking for outdated casks..."
  outdated, deprecated = compile

  outdated(outdated)
  deprecated(deprecated)
end

Instance Method Details

#compileObject



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/bct/tasks/outdated.rb', line 17

def compile
  outdated = []
  deprecated = []

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

    outdated << cask if cask.outdated?
    deprecated << cask if cask.deprecated?
  end
  [outdated, deprecated]
end

#deprecated(casks) ⇒ Object



44
45
46
47
48
49
50
51
# File 'lib/bct/tasks/outdated.rb', line 44

def deprecated(casks)
  return if casks.empty?
  handle(casks, 'deprecated') do |dep_casks|
    dep_casks.map! { |c| [c.name] }
    output = dep_casks.unshift(['Package'])
    print_table(output)
  end
end

#handle(casks, adverb) {|casks| ... } ⇒ Object

Yields:

  • (casks)


53
54
55
56
57
# File 'lib/bct/tasks/outdated.rb', line 53

def handle(casks, adverb)
  puts "#{adverb.capitalize} packages\n------------------"
  yield casks
  puts "\n"
end

#outdated(casks) ⇒ Object



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

def outdated(casks)
  return say "\nThere are no outdated casks", :yellow if casks.empty?
  handle(casks, 'outdated') do |outdated_casks|
    outdated_casks.map! do |c|
      [c.name, c.installed_version, c.current_version]
    end

    headers = ['Package', 'Installed Version', 'New Version']
    output = outdated_casks.unshift(headers)
    print_table(output)
  end
end