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