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