display runtime gem information in ./Gemfile
#!/usr/bin/env ruby
require 'ansi/code'
require 'bundler'
require 'json'
require 'open-uri'
class Integer
def to_currency
self.to_s.reverse.gsub(/(\d{3})(?=\d)/, '\1,').reverse
end
end
include ANSI::Code
begin
Bundler.definition.dependencies.select{ |i| i.groups.include? :default }.each do |dependency|
begin
json = JSON.parse(open("http://rubygems.org/api/v1/gems/#{dependency.name}.json").read)
name = json['name']
authors = json['authors']
downloads = json['downloads'].to_currency
project_uri = json['project_uri']
doc_uri = json['documentation_uri']
src_uri = json['source_code_uri']
info = json['info'].split("\n").first.strip
puts green { name } + ' (by ' + authors + ')'
puts 'Downloads: ' + blue { downloads }
puts 'Project : ' + cyan { underline { project_uri } } if project_uri
puts 'Document : ' + cyan { underline { doc_uri } } if doc_uri
puts 'Source : ' + cyan { underline { src_uri } } if src_uri
puts info
puts '-' * 60
rescue OpenURI::HTTPError => e
puts green { dependency.name }
puts 'Source : ' + cyan { underline { dependency.source } }
puts '-' * 60
end
end
rescue => e
puts "Error: #{e}"
end