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