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