Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/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
- #
- # 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 {|a|
- all_rails = Gems.versions(a).map{|r| r['number'] }
- release_versions = all_rails.select{|v| v =~ /^\d+.\d+(.\d+)*$/ }
- latest_versions = release_versions.inject([]) { |acc, i|
- if (acc.empty? || i[0] != acc.last[0])
- acc << i
- else
- acc
- end
- }
- results[a] = { vs: latest_versions, cv: gemhash[a].first.version}
- }
- results
- end
- if (ARGV.count > 0)
- # If list of gems on command line, discover versions of them, ignoring ones
- # that are not installed locally.
- # Yes, you could collapse all this into one line but let's be able to read it, ok?
- installed_gems = Gem::Specification.group_by{|g| g.name}
- arg_gems = ARGV.select{|g| installed_gems.keys.include?(g)}
- filtered_gems = installed_gems.select{|g| arg_gems.include?(g)}
- STDOUT.puts scab(filtered_gems).to_json
- else
- # 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
- end
Add Comment
Please, Sign In to add comment