Find Out What Dependencies A Ruby Gem Has, Gem Dependency

Earlier this afternoon I was working on a development server that has a web server, a PostgreSQL database, Ruby, and rubygems installed on it. I was curious to find out if a specific gem I was about to install had any dependencies or other gems that would also be installed as dependents of the gem I wanted to test. Below I describe how to find out the dependencies of a specific gem by querying the remote server but also how to download a specific gem version to see what gems are dependents.

Query Remote Ruby Gem Server To Find Out Gem Dependencies:

Locating the dependencies of a gem is fairly easy using the below syntax though you may run into issues on older gems so following the below syntax is a second example where the gem can be downloaded and then analyzed for dependencies.

[root@dev gems]# gem dependency ar_mailer --remote
Gem ar_mailer-1.3.1
  hoe (>= 1.2.2, runtime)

Gem ar_mailer-1.5.1
  rubyforge (>= 2.0.3, development)
  gemcutter (>= 0.2.1, development)
  minitest (>= 1.5.0, development)
  minitest (~> 1.3, development)
  hoe (>= 2.5.0, development)

Gem ar_mailer_generator-1.0.0
  ar_mailer (> 0.0.0, runtime)
  hoe (>= 1.2.2, runtime)

Gem ar_mailer_rails3-2.1.10

Gem ar_mailer_service-0.1.1
  win32-service (= 0.5.2, runtime)
  ar_mailer (>= 1.3.1, runtime)
  hoe (>= 1.4.0, runtime)

[root@dev gems]#

I used ar_mailer in the example above because it provides a real world view of what you might see when attempting to query a remove server to see what dependencies a specific gem has. We are most interested in the first two sections of data that are returned including the dependencies for ar_mailer 1.3.1 and the dependencies for ar_mailer 1.5.1. Notice how the older version of the ar_mailer gem only requires the hoe gem however the newer version of ar_mailer requires hoe, minitest, gemcutter, and rubyforge. You can also query a remote server about a the dependencies of a specific gem version as shown below.

Query Remote Gem Server About The Dependencies Of A Specific Gem Version:

[root@dev gems]# gem dependency ar_mailer --remote --version="1.3.1"
Gem ar_mailer-1.3.1
  hoe (>= 1.2.2, runtime)

[root@dev gems]# gem dependency ar_mailer --remote --version="1.5.1"
Gem ar_mailer-1.5.1
  rubyforge (>= 2.0.3, development)
  gemcutter (>= 0.2.1, development)
  minitest (>= 1.5.0, development)
  minitest (~> 1.3, development)
  hoe (>= 2.5.0, development)

[root@dev gems]#

As you can see above there are two examples to show that the remote server is returning the correct dependencies based on the gem version we are querying about. Now if the remote server doesn’t return any results or states that the gem is unknown as shown below then you can instead download the gem and query the gem file itself to obtain the list of dependencies.

Gem Server: ERROR Unknown gem

[root@dev gems]# gem specification treetop --version="1.2.4" --remote
ERROR:  Unknown gem 'treetop'
[root@dev gems]#

Download Gem Using Gem Fetch:

[root@dev gem-test]# gem fetch treetop
Downloaded treetop-1.4.3
[root@dev gem-test]# gem fetch treetop --version="1.2.4"
Downloaded treetop-1.2.4

Again there are two examples above. The first shows that the gem server will always return the latest gem version if the version is not specified and the second example displayed above shows that you can specify a gem version using the –version switch. After issuing the “gem fetch” command a .gem file will have been downloaded. In the above example treetop-1.4.3.gem and treetop-1.2.4.gem were both downloaded and you can use “gem specification <filename>” to find out what the dependencies are as shown in the below example.

Query Gem File For List Of Gem Dependencies:

[root@dev gem-test]# gem specification treetop-1.2.4.gem
--- !ruby/object:Gem::Specification
name: treetop
version: !ruby/object:Gem::Version
  version: 1.2.4
platform: ruby
authors:
- Nathan Sobo
autorequire: treetop
bindir: bin
cert_chain: []

date: 2008-06-01 09:00:00 -05:00
default_executable:
dependencies:
- !ruby/object:Gem::Dependency
  name: polyglot
  version_requirement:
  version_requirements: !ruby/object:Gem::Requirement
    requirements:
    - - ">="
      - !ruby/object:Gem::Version
        version: "0"
    version:
description:
email: nathansobo@gmail.com
executables:
- tt
extensions: []

extra_rdoc_files: []

files:
- README
- Rakefile
- lib/metagrammar.rb
- lib/treetop
- lib/treetop/bootstrap_gen_1_metagrammar.rb
- lib/treetop/compiler
- lib/treetop/compiler/grammar_compiler.rb
- lib/treetop/compiler/lexical_address_space.rb
- lib/treetop/compiler/metagrammar.rb
- lib/treetop/compiler/metagrammar.treetop
- lib/treetop/compiler/node_classes
- lib/treetop/compiler/node_classes/anything_symbol.rb
- lib/treetop/compiler/node_classes/atomic_expression.rb
- lib/treetop/compiler/node_classes/character_class.rb
- lib/treetop/compiler/node_classes/choice.rb
- lib/treetop/compiler/node_classes/declaration_sequence.rb
- lib/treetop/compiler/node_classes/grammar.rb
- lib/treetop/compiler/node_classes/inline_module.rb
- lib/treetop/compiler/node_classes/nonterminal.rb
- lib/treetop/compiler/node_classes/optional.rb
- lib/treetop/compiler/node_classes/parenthesized_expression.rb
- lib/treetop/compiler/node_classes/parsing_expression.rb
- lib/treetop/compiler/node_classes/parsing_rule.rb
- lib/treetop/compiler/node_classes/predicate.rb
- lib/treetop/compiler/node_classes/repetition.rb
- lib/treetop/compiler/node_classes/sequence.rb
- lib/treetop/compiler/node_classes/terminal.rb
- lib/treetop/compiler/node_classes/transient_prefix.rb
- lib/treetop/compiler/node_classes/treetop_file.rb
- lib/treetop/compiler/node_classes.rb
- lib/treetop/compiler/ruby_builder.rb
- lib/treetop/compiler.rb
- lib/treetop/ruby_extensions
- lib/treetop/ruby_extensions/string.rb
- lib/treetop/ruby_extensions.rb
- lib/treetop/runtime
- lib/treetop/runtime/compiled_parser.rb
- lib/treetop/runtime/interval_skip_list
- lib/treetop/runtime/interval_skip_list/head_node.rb
- lib/treetop/runtime/interval_skip_list/interval_skip_list.rb
- lib/treetop/runtime/interval_skip_list/node.rb
- lib/treetop/runtime/interval_skip_list.rb
- lib/treetop/runtime/syntax_node.rb
- lib/treetop/runtime/terminal_parse_failure.rb
- lib/treetop/runtime/terminal_syntax_node.rb
- lib/treetop/runtime.rb
- lib/treetop.rb
- bin/tt
- doc/contributing_and_planned_features.markdown
- doc/grammar_composition.markdown
- doc/index.markdown
- doc/pitfalls_and_advanced_techniques.markdown
- doc/semantic_interpretation.markdown
- doc/site.rb
- doc/sitegen.rb
- doc/syntactic_recognition.markdown
- doc/using_in_ruby.markdown
- examples/lambda_calculus
- examples/lambda_calculus/arithmetic.rb
- examples/lambda_calculus/arithmetic.treetop
- examples/lambda_calculus/arithmetic_node_classes.rb
- examples/lambda_calculus/arithmetic_test.rb
- examples/lambda_calculus/lambda_calculus
- examples/lambda_calculus/lambda_calculus.rb
- examples/lambda_calculus/lambda_calculus.treetop
- examples/lambda_calculus/lambda_calculus_node_classes.rb
- examples/lambda_calculus/lambda_calculus_test.rb
- examples/lambda_calculus/test_helper.rb
has_rdoc: false
homepage: http://functionalform.blogspot.com
licenses:
post_install_message:
rdoc_options: []

require_paths:
- lib
required_ruby_version: !ruby/object:Gem::Requirement
  requirements:
  - - ">="
    - !ruby/object:Gem::Version
      version: "0"
  version:
required_rubygems_version: !ruby/object:Gem::Requirement
  requirements:
  - - ">="
    - !ruby/object:Gem::Version
      version: "0"
  version:
requirements: []

rubyforge_project:
rubygems_version: 1.3.5
signing_key:
specification_version: 2
summary: A Ruby-based text parsing and interpretation DSL
test_files: []

[root@dev gem-test]#

The above information should provide enough information to locate the gem dependencies of any gem regardless of how old the gem is.

Ruby Cookbook (Cookbooks (O'Reilly)) (Paperback)

By (author): Lucas Carlson, Leonard Richardson


List Price: $49.99 USD
New From: $19.99 USD In Stock
Used from: $10.97 USD In Stock


List Price: $39.99 USD
New From: $20.90 USD In Stock
Used from: $7.94 USD In Stock

Share