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