Skip to content

Instantly share code, notes, and snippets.

@unak
Created January 29, 2015 16:59
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save unak/ce178a0a5ccebab6bf5b to your computer and use it in GitHub Desktop.
Save unak/ce178a0a5ccebab6bf5b to your computer and use it in GitHub Desktop.
Show dependency tree of Rails
#!ruby
require "rubygems/dependency"
require "rubygems/spec_fetcher"
def fetch_spec(dep)
dep = Gem::Dependency.new(dep, :runtime) unless dep.is_a?(Gem::Dependency)
Gem::SpecFetcher.fetcher.spec_for_dependency(dep).first.map{|spec, src| spec}.last
end
$spec_cache = []
def traverse_dependencies(spec, indent = 0)
name = [spec.name, spec.version].join('-')
print ' ' * (indent * 2)
print name
if $spec_cache.include?(name)
puts ' (snip)'
return
end
puts
$spec_cache << name
spec.runtime_dependencies.each do |dep|
traverse_dependencies(fetch_spec(dep), indent + 1)
end
end
traverse_dependencies(fetch_spec("rails"))
@unak
Copy link
Author

unak commented Jan 29, 2015

result:

rails-4.2.0
  activesupport-4.2.0
    i18n-0.7.0
    json-1.8.2
    tzinfo-1.2.2
      thread_safe-0.3.4
    minitest-5.5.1
    thread_safe-0.3.4 (snip)
  actionpack-4.2.0
    activesupport-4.2.0 (snip)
    rack-1.6.0
    rack-test-0.6.3
      rack-1.6.0 (snip)
    rails-html-sanitizer-1.0.1
      loofah-2.0.1
        nokogiri-1.6.6.2
          mini_portile-0.6.2
    rails-dom-testing-1.0.5
      nokogiri-1.6.6.2 (snip)
      activesupport-4.2.0 (snip)
      rails-deprecated_sanitizer-1.0.3
        activesupport-4.2.0 (snip)
    actionview-4.2.0
      activesupport-4.2.0 (snip)
      builder-3.2.2
      erubis-2.7.0
      rails-html-sanitizer-1.0.1 (snip)
      rails-dom-testing-1.0.5 (snip)
  actionview-4.2.0 (snip)
  activemodel-4.2.0
    activesupport-4.2.0 (snip)
    builder-3.2.2 (snip)
  activerecord-4.2.0
    activesupport-4.2.0 (snip)
    activemodel-4.2.0 (snip)
    arel-6.0.0
  actionmailer-4.2.0
    actionpack-4.2.0 (snip)
    actionview-4.2.0 (snip)
    activejob-4.2.0
      activesupport-4.2.0 (snip)
      globalid-0.3.0
        activesupport-4.2.0 (snip)
    mail-2.6.3
      mime-types-2.4.3
    rails-dom-testing-1.0.5 (snip)
  activejob-4.2.0 (snip)
  railties-4.2.0
    activesupport-4.2.0 (snip)
    actionpack-4.2.0 (snip)
    rake-10.4.2
    thor-0.19.1
  bundler-1.7.12
  sprockets-rails-2.2.4
    sprockets-2.12.3
      hike-1.2.3
      multi_json-1.10.1
      rack-1.6.0 (snip)
      tilt-1.4.1
    actionpack-4.2.0 (snip)
    activesupport-4.2.0 (snip)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment