Question

I would like to load a Gemfile using the Bundler object in ruby and be able to view the gems, dependencies, and various groups. Since this obviously isn't documented, does anyone with a knowledge of the bundler source know how to do this?

Was it helpful?

Solution

After poking around the Bundler source code... I found you can do this...

require 'bundler'
b = Bundler::Dsl.new
b.eval_gemfile('Gemfile')  # point to your Gemfile path

b.dependencies.each do |g|
  puts g.name
  puts g.groups
  puts g.requirements_list
end

@sevenseacat You might have to poke around a bit more to lookup other gems a particular gem is dependent on, but hopefully that gets you started. It certainly accomplished what I was looking to do.

OTHER TIPS

The only way, that I'm aware of, to get a representation of what groups hold what dependencies at which versions would be through bundle viz.

Via the bundle viz documentation, or by $ bundle help viz, you can see that the -V option will output the versions in the graph generated.

Note, you'll need to install dependencies (typically ruby-graphviz). You'll get an image which looks something similar to:

This example image from one of my discarded projects

Note, this may not be the easiest way to parse this data; but, it is the available method.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top