diff options
| author | AnastasiaSulyagina | 2016-08-18 22:11:42 +0300 |
|---|---|---|
| committer | AnastasiaSulyagina | 2016-08-19 14:50:14 +0300 |
| commit | e81f4ab7deeb40308f240be5ea00091fc8786d7a (patch) | |
| tree | b5418f9149de71c0f05f90cb2b39ab47f46e27b4 /Library/Homebrew/cask/developer/examples/brewcask-doutdated.rb | |
| parent | 5c7c9de669025bbe4cad9829be39c5cf3b31ad25 (diff) | |
| download | brew-e81f4ab7deeb40308f240be5ea00091fc8786d7a.tar.bz2 | |
init
Diffstat (limited to 'Library/Homebrew/cask/developer/examples/brewcask-doutdated.rb')
| -rwxr-xr-x | Library/Homebrew/cask/developer/examples/brewcask-doutdated.rb | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/Library/Homebrew/cask/developer/examples/brewcask-doutdated.rb b/Library/Homebrew/cask/developer/examples/brewcask-doutdated.rb new file mode 100755 index 000000000..de0234c2f --- /dev/null +++ b/Library/Homebrew/cask/developer/examples/brewcask-doutdated.rb @@ -0,0 +1,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 |
