Skip to content

Instantly share code, notes, and snippets.

@cbaclig
Created February 25, 2010 07:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cbaclig/314340 to your computer and use it in GitHub Desktop.
Save cbaclig/314340 to your computer and use it in GitHub Desktop.
Patch to gem_plugin/lib/gem_plugin.rb to support multiple Gem paths
def load(needs = {})
sdir = File.join(Gem.dir, "specifications")
# Patch to support multiple Gem directories
# gems = Gem::SourceIndex.from_installed_gems(sdir)
gems = Gem::SourceIndex.from_installed_gems
needs = needs.merge({"gem_plugin" => INCLUDE})
gems.each do |path, gem|
# don't load gems more than once
next if @gems.has_key? gem.name
check = needs.dup
# rolls through the depends and inverts anything it finds
gem.dependencies.each do |dep|
# this will fail if a gem is depended more than once
if check.has_key? dep.name
check[dep.name] = !check[dep.name]
end
end
# now since excluded gems start as true, inverting them
# makes them false so we'll skip this gem if any excludes are found
if (check.select {|name,test| !test}).length == 0
# looks like no needs were set to false, so it's good
# Previously was set wrong, we already have the correct gem path!
#gem_dir = File.join(Gem.dir, "gems", "#{gem.name}-#{gem.version}")
# Patch to support multple Gem directories, CFB
# gem_dir = File.join(Gem.dir, "gems", path)
gem_dir = ""
Gem.path.each do |gem_path|
gem_dir = File.join(gem_path, "gems", path)
break if File.exists?(gem_dir)
end
require File.join(gem_dir, "lib", gem.name, "init.rb")
@gems[gem.name] = gem_dir
end
end
return nil
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment