Gem.latest_load_paths works for all installed gems, even if they're =A0
not activated. =A0You'll need to use Gem::Specification#full_gem_path =A0
and Gem::Specification#require_path.
Needing to know where the gem lives is a sign that you're doing =A0
something wrong though.
I'm doing a little meta-programming in this case -- I've created a
function to find "plugins". So I need to search through the $LOAD_PATH
and Gems. But I'm all ears if there is another way to do it. Here's
the code:
# =3D Plugin Handler
#
# Find plugins across various library managers.
#
module Plugin
extend self
DIRECTORY =3D 'plugin'
# Find plugins, searching through standard $LOAD_PATH,
# Roll Libraries and RubyGems.
#
# Provide a +match+ file glob to find plugins.
#
# Plugins.find('syckle/*')
#
def find(match)
plugins =3D []
# Standard $LOAD_PATH
$LOAD_PATH.uniq.each do |path|
list =3D Dir.glob(File.join(path, DIRECTORY, match))
#dirs =3D dirs.select{ |d| File.directory?(d) }
list =3D list.map{ |d| d.chomp('/') }
plugins.concat(list)
end
# ROLL (load latest or current versions only)
if defined?
:Roll)
::Roll::Library.ledger.each do |name, lib|
lib =3D lib.sort.first if Array=3D=3D=3Dlib
lib.load_path.each do |path|
find =3D File.join(lib.location, path, DIRECTORY, match)
list =3D Dir.glob(find)
list =3D list.map{ |d| d.chomp('/') }
plugins.concat(list)
end
end
end
# RubyGems (load latest versions only)
# TODO: need current versions
if defined?
:Gem)
Gem.latest_load_paths do |path|
list =3D Dir.glob(File.join(path, DIRECTORY, match))
list =3D list.map{ |d| d.chomp('/') }
plugins.concat(list)
end
end
plugins
end
# Shortcut for #find.
#
# Plugins['syckle/*']
#
alias_method :[], :find
end
Also, I wonder how Ruby 1.9 might effect this. Are the latest gem
paths added to the $LOAD_PATH by default in 1.9?