Created
July 7, 2010 04:30
-
-
Save lsegal/466308 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'json' | |
require 'open-uri' | |
class DependencyChecker | |
def initialize(*gems) | |
@gems = gems.flatten | |
@dep_cache = {} | |
end | |
def all_dependencies | |
deps = @gems.flatten | |
loop do | |
size = deps.size | |
deps.dup.each {|dep| deps |= dependencies_for(dep) } | |
break if size == deps.size | |
end | |
deps.sort - @gems | |
end | |
private | |
def dependencies_for(gem) | |
return @dep_cache[gem] if @dep_cache[gem] | |
#puts "Checking dependencies for #{gem}" | |
json = JSON.parse(open("http://rubygems.org/api/v1/gems/#{gem}.json").read) | |
@dep_cache[gem] = json['dependencies']['runtime'].map {|g| g['name'] }.uniq | |
end | |
end | |
if ARGV.empty? | |
print "Enter gem names: " | |
deps = gets.strip.split(/\s+|,/).map {|x| x.empty? ? nil : x }.compact | |
else | |
deps = ARGV | |
end | |
puts "Recursive dependencies for #{deps.join(', ')}:" | |
puts DependencyChecker.new(*deps).all_dependencies |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment