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