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 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)
Check system dependencies for a gem
Use the gem dependency GEMNAME
command.
See the documentation here.
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 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 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.
How to check gem dependencies from a specific version of a Gem?
Try:
gem dependency --help
gem dependency rails_admin --version
update by rmagnum2002
without --version
user@user:~/projects/new_work$ gem dependency devise
Gem devise-3.0.4
bcrypt-ruby (~> 3.0)
orm_adapter (~> 0.1)
railties (< 5, >= 3.2.6)
warden (~> 1.2.3)
Gem devise-3.2.2
bcrypt-ruby (~> 3.0)
orm_adapter (~> 0.1)
railties (< 5, >= 3.2.6)
thread_safe (~> 0.1)
warden (~> 1.2.3)
with --version
user@user:~/projects/new_work$ gem dependency devise --version 3.0.4
Gem devise-3.0.4
bcrypt-ruby (~> 3.0)
orm_adapter (~> 0.1)
railties (< 5, >= 3.2.6)
warden (~> 1.2.3)
when no such version found installed on your system or bundler
user@user:~/projects/new_work$ gem dependency devise --version 3.0.6
No gems found matching devise (= 3.0.6)
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)
Related Topics
How to Mark a Cucumber Scenario as Pending
In Ruby How to Use Class Level Local Variable? (A Ruby Newbie's Question)
How Can Bundler/Gemfile Be Configured to Use Different Gem Sources During Development
How to Convert Any Method to Infix Operator in Ruby
How to Find Current Abstract Route in Rails Middware
Access Google Contacts API on Ruby
Is There a Ruby Method That Just Returns the Value of a Block
Failure: Expected 0 to Be >= 1 on Ruby on Rails
How to Strip Leading and Trailing Quote from String, in Ruby
What Does ["String"].Pack('H*') Mean
How Do Version Numbers Work for Mri Ruby
Skip/Disable Force_Ssl for Particular Controller in Rails
Integrating @Font-Face Files into Rails Asset Pipeline