Reading Gem Specifications

When I was looking into the problem with installing deep_test with Rubygems 0.9.4, I wanted to see if the bug occurred with other gems. I noticed that the gem specification command will display the spec for a gem that is installed locally, but I couldn't figure out how to get it to display the specification from a gem file. I already had an rsync mirror of the gem repository, so I wanted to go through all the files to look for any gems built with 0.9.5 without a platform. Fortunately, Rubygems comes with a really easy way to read the specification from a gem file. Here's the script I used:


require "rubygems"
require "rubygems/package"

Dir["/Volumes/Backup/rubygems/*.gem"].each do |gem_file|
  begin
    Gem::Package.open(gem_file) do |gem|
      spec = gem.metadata
      if spec.platform == "" && spec.rubygems_version == "0.9.5"
        puts "#{spec.name} #{spec.version.version}"
      end
    end
  rescue
  end
end