blob: de0234c2f172ee911a49b8dd630da36930ed5d83 (
plain)
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
40
41
42
43
|
#!/usr/bin/env ruby
#
# Generously contributed by Markus Doits
# https://github.com/doits
# (c) 2014 MIT license
#
require "rubygems"
class Hbc
def installed_version?
!installed_version.nil?
end
def installed_version
# returns latest installed version if possible
Pathname.glob(caskroom_path.join("*")).map(&:basename).sort do |x, y|
Gem::Version.new(x) <=> Gem::Version.new(y) # throws exception if invalid version is provided ...
end.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 Hbc::Scopes
module ClassMethods
def upgradable
Hbc.installed.select(&:update_available?)
end
end
end
upgradable_casks = Hbc.upgradable
puts upgradable_casks.empty? && "No outdated packages" || upgradable_casks
|