RubyGem Dependencies
posted by hitesh on 2007-02-20
The other day, a friend of mine told me about some rubygem problems she was having. Her company's firewall was a bit flaky and rubygems wasn't able to auto grab dependencies for her. What she wanted was a way to determine a gem's dependencies without yet installing it.
The gem dependency command is supposed to have an option to let you see the dependencies on a gem -- but it only works on already installed gems. Then there's the gem specification command. Great, it takes a gemfile as input, just what she needs. Unfortunately, it's a case of false advertising. Even though the docs say it will take a gemfile, it really only works on installed gems.
% gem dependency rails-1.2.1.gem
No match found for rails-1.2.1.gem (> 0))
% gem specification rails-1.2.1.gem
ERROR: Unknown gem rails-1.2.1.gem
So I did some investigation and ended up writing a few lines of Ruby. Save the following in a file named, gemdep.rb.
require 'rubygems/format'
Gem::Format.from_file_by_path(ARGV[0]).spec.dependencies.each do |d|
puts "#{d.name} #{d.version_requirements.as_list}"
end
And test it as so
% ruby gemdep.rb rails-1.2.1.gem
rake >= 0.7.1
activesupport = 1.4.0
activerecord = 1.15.1
actionpack = 1.13.1
actionmailer = 1.3.1
actionwebservice = 1.2.1
The solution is always just a few lines of Ruby, isn't it? I sometimes wonder if world hunger couldn't be solved by a few well written lines of Ruby and
acts_as_plentiful :foodReferrers
- http://search.live.com/results.aspx?q=dependencies
- http://search.live.com/results.aspx?q=dependencies&form=QBHP
- http://www.google.com/search?q=ruby+gem+dependencies&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:en-US:official&client=firefox-a
- http://search.live.com/results.aspx?q=dependencies&mrt=en-us&FORM=LIVSOP
- http://www.google.ca/search?q=ruby+gem+dependencies&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:en-GB:official&client=firefox-a
- http://www.google.co.jp/search?q=Gem+Dependencies&hl=ja&safe=off&start=20&sa=N
- http://www.google.co.uk/search?hl=en&safe=off&client=firefox&rls=org.mozilla%3Aen-US%3Aunofficial&hs=Lvo&q=%22unknown+gem+rails+%3D%22&btnG=Search&meta=
- http://www.google.co.uk/search?hl=en&safe=off&q=installing+gem+dependencies&start=10&sa=N
- http://www.google.com
- http://www.google.com.au/search?hl=en&client=firefox-a&rls=org.mozilla:en-US:official&hs=xHG&sa=X&oi=spell&resnum=0&ct=result&cd=1&q=ruby+gem+dependency&spell=1
About
Hitesh wrote his first program on a punch card in 1979 ... he's been debugging it ever since.