Skip to content

Instantly share code, notes, and snippets.

Last active Jul 21, 2018
What would you like to do?
#!/usr/bin/env ruby
require 'gems'
require 'bundler/setup'
require 'json'
require 'rubygems'
# Find the current version of a gem you are using, then find the latest
# version of the gem and put in a reminder that theres been updates.
# gemnasium used to do this but then they got bought and that service is
# gone, I think it was bundled into github
# Given the name of a gem, release_versions will return all released
# version strings -- it exludes everything that isn't of the form
# of dot separated numbers, i.e. no betas or rc1s or that kind of thing
# Goes to the network -- Rubygems only -- so not useful for private
# gems, but ye should be in charge of those already.
def release_versions(name)
Gems.versions(name).map { |r| r['number'] }.select { |v| v =~ /^\d+.\d+(.\d+)*$/ }
# Scab returns a hash of the latest major versions of the gems in the hash
# which looks like { "gemname" : [array of gemspecs]}
def scab(gemhash)
# This needs a sorted array -- you get it from Gems.versions anyway
# so no need to do any sorts here directly, waste of time.
# Should probably be able to do filters too, but eh that's not important
results = {}
gemhash.keys.each do |name|
top_versions = release_versions(name).inject([]) do |acc, i|
if acc.empty? || i[0] != acc.last[0]
acc << i
results[a] = { vs: top_versions, cv: gemhash[name].first.version }
if ARGV.count > 0
# If list of gems on command line, discover versions of them, ignoring ones
# that are not installed locally
installed_gems = Gem::Specification.group_by(&:name)
arg_gems = { |g| installed_gems.key?(g) }
filtered_gems = { |g| arg_gems.include?(g) }
STDOUT.puts scab(filtered_gems).to_json
# If no list of gems on command line, ask Bundler what's in use
# according to the local Gemfile.lock
STDOUT.puts scab(Bundler.load.specs.to_hash).to_json
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment