[Rubygems-developers] Automating gems

Eric Hodel drbrain at segment7.net
Sat Mar 17 07:52:56 EDT 2007

On Mar 14, 2007, at 14:47, Patrick Hurley wrote:

> Sorry, if I should have been able to find some docs to point me in the
> right direction, but so far here is what I figured out from trial and
> error and some source code reading.
> I want to unpack a gem already on my machine:
> gem unpack a_gem
> Then I want to retrieve the gem spec
> gem specification a_gem
> (then more stuff but this will get me started)
> So far I have the simple code:
> require "rubygems"
> Gem.manage_gems
> if gem = ARGV.first
>   puts "Processing #{gem}"
>   runner = Gem::GemRunner.new
>   puts "Unpack #{gem}"
>   runner.run ['unpack', gem]
>   runner.run(['specification', gem])
> end
> This works; however, the run command displays to the screen. Is there
> an easy way to capture its output? I see there is a default interface
> object, with a method called say I could grab, but that seems pretty
> messy. I could also grab the stdout handle and play games there, but
> again, I feel I am missing something.

Don't use the runner interface at all, it doesn't do anything you  
need, and adds a bunch of crap you don't (redirecting output).

Just call the Gem::Installer#unpack method directly.

$ ri Gem::Installer#unpack
-------------------------------------------------- Gem::Installer#unpack
      Unpacks the gem into the given directory.

Just use to_yaml or to_ruby on Gem::Specification.

More information about the Rubygems-developers mailing list