Created
December 29, 2008 20:45
-
-
Save kesor/41380 to your computer and use it in GitHub Desktop.
handle vendor/gems in rails 2.2 as a dir for gems, not foreign alien shit that it is today
This file contains hidden or 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
# see mail reply in http://groups.google.com/group/haml/msg/12f63d9dff34a1d5 | |
# with explanation about how/why this works better than rails 2.2 | |
module Rails | |
class VendorGemSourceIndex | |
def gemspec_filename(d) | |
File.join(d,"#{File.basename(d)}.gemspec") | |
end | |
def load_specification(d) | |
Dir.chdir(d) { return eval(File.read(gemspec_filename(d))) } | |
end | |
def refresh! | |
# reload the installed gems | |
@installed_source_index.refresh! | |
vendor_gems = {} | |
# handle vendor Rails gems - they are identified by having loaded_from set to "" | |
# we add them manually to the list, so that other gems can find them via dependencies | |
Gem.loaded_specs.each do |n, s| | |
next unless s.loaded_from.empty? | |
vendor_gems[s.full_name] = s | |
end | |
# load specifications from vendor/gems | |
Dir[File.join(Rails::GemDependency.unpacked_path, '*')].each do |d| | |
spec = load_specification(d) | |
spec.loaded_from = gemspec_filename(d) | |
# finally, swap out full_gem_path | |
class << spec | |
def full_gem_path=(path) | |
@full_gem_path = path | |
end | |
def full_gem_path | |
@full_gem_path | |
end | |
end | |
spec.full_gem_path = d | |
vendor_gems[File.basename(d)] = spec | |
end | |
@vendor_source_index = Gem::SourceIndex.new(vendor_gems) | |
end | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment