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 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
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.
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.
Ruby - How to find out all dependencies of a given Gem in a .rb file?
You can yank the code out of lib/rubygems/commands/dependency_command.rb
. Here's a simple method I made.
require 'rubygems/commands/dependency_command'
def get_dependencies name, local = true
cmd = Gem::Commands::DependencyCommand.new
dependency = cmd.gem_dependency name, nil, nil
specs =
if local
dependency.matching_specs.uniq.sort
else
cmd.fetch_remote_specs(dependency).uniq.sort
end
dependencies = []
specs.each do |spec|
dependencies.concat spec.dependencies.sort_by { |dep| dep.name }.map { |dep| [dep.name, dep.requirement] }
end
dependencies
end
puts get_dependencies('diamond_shell', false)
Get all dependencies of a specific version of a Gem on RubyGems
I found the solution. The best (and only way) is to use the dependency file of a gem, who list all dependencies of each version of the gem.
To get this file, it's necessary to call the dependency address of the API : http://guides.rubygems.org/rubygems-org-api/#misc-methods (the last one).
After that, this few line do all the stuff to get dependencies of a specific version :
url = URI("https://rubygems.org/api/v1/dependencies?gems=#{gem_name}")
dependencies = Net::HTTP.get(url)
data = Marshal.load(dependencies).each do |dependency|
break dependency if dependency[:number] == gem_version
end
How to list gem dependencies for some non-intalled gem?
I know that this is a bit of a necro, but I think that you can use gem install --explain rails.
from http://guides.rubygems.org/command-reference/#gem-install
--explain - Rather than install the gems, indicate which would be installed
You may have to run that command from another system that CAN access the rubygems.org server, get the list of gems, pull them down, and install them on your system instead of hitting rubygems directly (till you get your network problem figured out)
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 check system package dependency of a gem
You can't, per se. The dependency is on the libcurl headers, so you could try to find those headers in the available search paths, and then make a recommendation of which package to install based on the platform being installed on, but the libcurl headers could be installed by any number of packages, or even from source, so there's no one way to say "curb requires libcurl-devel" in a general case.
Related Topics
How to Execute 2 or More Commands in the Same Ssh Session
Pg::Error: Error: Invalid Byte Sequence for Encoding "Utf8": 0Xfc
Flash Message with HTML_Safe from the Controller in Rails 4 (Safe Version)
How to Define a Method in Ruby Using Splat and an Optional Hash at the Same Time
Why Does 6.Times.Map Work in Ruby 1.8.7 But Not 1.8.6
Rails Not Rolling Back Transaction After Failed Save()
Respond_With Redirect with Notice Flash Message Not Working
Why Does Hash#Select and Hash#Reject Pass a Key to a Unary Block
Net-Ssh and Remote Environment
How to Simplify or Clean Up This Anagram Method
Ruby: How to Call Function Before It Is Defined
Yaml::Load Raises Undefined Class/Module Error