Skip to content

Instantly share code, notes, and snippets.

@chetan
Created November 21, 2014 20:24
Show Gist options
  • Save chetan/8cb79727674056109d7a to your computer and use it in GitHub Desktop.
Save chetan/8cb79727674056109d7a to your computer and use it in GitHub Desktop.
List all runtime dependencies for the given gem
#!/usr/bin/env ruby
target = ARGV.shift.strip
class App
def initialize
@deps = []
end
def resolve(gem)
if @deps.include? gem or gem.strip.empty? then
return
end
# puts "resolving: " + gem
@deps << gem
# cmd = "gem dependency " + gem + " | egrep -v ^Gem | egrep -v 'development\\)$' | awk '{print $1}'"
# gems = `#{cmd}`
# gems.strip.split(/\n/).each { |g| resolve(g) }
specs = Gem::Dependency.new(gem).matching_specs
return if !specs or specs.empty?
specs.first.dependencies.each do |d|
next if d.type == :development
resolve(d.name)
end
return @deps
end
end
puts "listing all runtime dependencies for #{target}"
puts App.new.resolve(target).sort
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment