How to Trace and Check Dependencies in Bundled Ruby Gems

How to trace and check dependencies in bundled Ruby gems

To see a visual representation of the dependency tree run bundle viz:

apt-get install graphviz && gem install ruby-graphviz && bundle viz

It will generate a PNG file of the tree.

How to see the dependency tree just from Gemfile?

gem dependency (with no args) should show you all gems from current system with their dependencies.

bundle exec gem dependency will show you for the current Gemfile

Edit:

You can also do gem dependency -R (or just dep instead of dependency) if you want to find out which gems use specific (or all) gems.

For deeper dependencies I'd parse output (regex maybe?) of first gem dependencies, pick gem's names and call gem dep on each of them, but that's just a loose idea.

How do I check that all the dependencies of my installed Ruby gems are satisfied?

I know you said you weren't interested in answers about Bundler, but…

Bundler will handle gem dependency resolution for you and is compatible with Rails 2.3. I've used Bundler with a number of Rails 2 apps and not had any problems with it.

There are instructions for installing Bundler on Rails 2.3 here: http://gembundler.com/rails23.html

How do I find out which gem has a specific dependency?

In the bash shell you can do:

gem dependency name_of_the_gem --reverse-dependencies

For instance:

$ gem dependency activesupport --reverse-dependencies                        
Gem activesupport-2.3.14
Used by
actionpack-2.3.14 (activesupport (= 2.3.14))
activerecord-2.3.14 (activesupport (= 2.3.14))
activeresource-2.3.14 (activesupport (= 2.3.14))

How do I figure out which gem(s) caused a particular gem to be bundled?

Normally Gemfile.lock documents which dependencies were generated from other dependencies, it's listed in a rough tree form, but you may have to do some digging to get to the right spot.

What does ~ mean in ruby gems dependencies?

It basically means greater than. or equal to, the last digit of the version.

i.e. "~> 1.0" is equivalent to ">= 1.0 and < 2.0". Thus 1.1, 1.5.2, 1.9.9 will all match.

Another example: "~> 1.1.0" would mean ">= 1.1 and < 1.2"

Refer also to: What does tilde-greater-than (~>) mean in Ruby gem dependencies?

Command for displaying a gem's dependencies?

The following information was pulled from the rubygems command reference linked below.

http://guides.rubygems.org/command-reference/#gem-dependency

The first command you're asking for is "gem dependency". Below is the command description.

gem dependency GEMNAME [options]

Options:
-v, --version VERSION Specify version of gem to uninstall
-r, --[no-]reverse-dependencies Include reverse dependencies in the output
-p, --pipe Pipe Format (name --version ver)

Common Options:
--source URL Use URL as the remote source for gems
-h, --help Get help on this command
--config-file FILE Use this config file instead of default
--backtrace Show stack backtrace on errors
--debug Turn on Ruby debugging

Arguments:
GEMNAME name of gems to show

Summary:
Show the dependencies of an installed gem

Defaults:
--version '> 0' --no-reverse

The second command you'll need is "gem install". Dependencies get installed automatically. Read the quote below from the command reference for more detail.

"gem install" will install the named
gem. It will attempt a local
installation (i.e. a .gem file in the
current directory), and if that fails,
it will attempt to download and
install the most recent version of the
gem you want.

If a gem is being installed remotely,
and it depends on other gems that are
not installed, then gem will download
and install those, after you have
confirmed the operation.

Bundler: find which gem depends on this?

You could try looking inside your Gemfile.lock file.
Dependencies are nested underneath what they are required by.



Related Topics



Leave a reply



Submit