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