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