forked from Homebrew/homebrew-cask
-
Notifications
You must be signed in to change notification settings - Fork 0
/
brewcask-doutdated.rb
executable file
·39 lines (32 loc) · 1.03 KB
/
brewcask-doutdated.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/usr/bin/env ruby
#
# Generously contributed by Markus Doits
# https://github.com/doits
# (c) 2014 MIT license
#
require 'rubygems'
class Cask
def installed_version?
!installed_version.nil?
end
def installed_version
# returns latest installed version if possible
Pathname.glob(caskroom_path.join('*')).map(&:basename).sort{|x,y|
Gem::Version.new(x) <=> Gem::Version.new(y) # throws exception if invalid version is provided ...
}.last rescue nil # ... return nil in this case
end
def update_available?
Gem::Version.correct?(version) && # we have something to compare against in Cask file ...
installed_version? && # ... we can determine current installed version ...
Gem::Version.new(installed_version) < Gem::Version.new(version) # ... compare
end
end
module Cask::Scopes
module ClassMethods
def upgradable
Cask.installed.select(&:update_available?)
end
end
end
upgradable_casks = Cask.upgradable
puts upgradable_casks.length == 0 && 'No outdated packages' || upgradable_casks