0ab684
#!/usr/bin/ruby
0ab684
0ab684
require 'rubygems/package'
0ab684
0ab684
module RubyGemsProv
0ab684
  module Helpers
0ab684
    # If there is some prelease version files, such as rc1 (i.e. non-numeric
0ab684
    # field), prepend this field by tilde instead of dot.
0ab684
    def self.normalize_prerelease(version)
0ab684
      if version.prerelease?
0ab684
        prerelease = version.version.sub /^#{version.release}\./, ''
0ab684
        "#{version.release}-0.1.#{prerelease}"
0ab684
      else
0ab684
        "#{version.release}-1"
0ab684
      end
0ab684
    end
0ab684
  end
0ab684
0ab684
  # Reports all functionality gem provides.
0ab684
  def self.provides
0ab684
    while filename = gets
0ab684
      filename.strip!
0ab684
      begin
0ab684
        specification = Gem::Specification.load filename
0ab684
0ab684
        puts "rubygem(#{specification.name}) = #{Helpers::normalize_prerelease(specification.version)}"
0ab684
      rescue => e
0ab684
        # Ignore all errors.
0ab684
      end
0ab684
    end
0ab684
  end
0ab684
end
0ab684
0ab684
if __FILE__ == $0
0ab684
  RubyGemsProv::provides
0ab684
end