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