Created
February 25, 2010 07:44
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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