public
Created

~/bin/gemdir

  • Download Gist
gemdir.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
#! /usr/bin/env ruby
# usage: gemdir gemname
#
# eg: cd `gemdir yajl`
#
require 'rubygems'
 
arg = ARGV.first
 
unless arg
puts File.join(Gem.dir, "gems")
exit
end
 
which = arg.dup
which << '*' if which
 
entries =
Dir[ File.join(Gem.dir, "gems", "#{ which }") ].select{|entry| test ?d, entry}.sort
 
case entries.size
when 0
abort "no gem #{ which }"
 
when 1
puts entries.first
 
else
all_same_name = entries.map{|e| File.basename(e).split('-').first}.uniq.size == 1
 
if all_same_name
puts entries.last
else
unless STDIN.tty?
warn "ambiguous gemname #{ arg.inspect }"
end
abort(entries.join("\n"))
end
end

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.