diff options
author | Seb Bacon <seb.bacon@gmail.com> | 2011-08-22 09:44:46 +0100 |
---|---|---|
committer | Seb Bacon <seb.bacon@gmail.com> | 2011-08-22 09:44:46 +0100 |
commit | 30e114c33a8b9890e2997b686b081c326dcb9ba2 (patch) | |
tree | edb335b919214873616845663ed31d28c074dabe | |
parent | 22aee5b911c4d1784a5ce7638fd01173b648a454 (diff) |
Ensure that recent Rails upgrade doesn't break compatibility with older versions of Rubygems (such as exist in Debian Lenny). Closes #145.
-rw-r--r-- | config/environment.rb | 6 | ||||
-rw-r--r-- | lib/old_rubygems_patch.rb | 42 |
2 files changed, 48 insertions, 0 deletions
diff --git a/config/environment.rb b/config/environment.rb index 606472740..73cab9201 100644 --- a/config/environment.rb +++ b/config/environment.rb @@ -28,6 +28,12 @@ load "config.rb" load "format.rb" load "debug_helpers.rb" load "util.rb" +# Patch Rails::GemDependency to cope with older versions of rubygems, e.g. in Debian Lenny +# Restores override removed in https://github.com/rails/rails/commit/c20a4d18e36a13b5eea3155beba36bb582c0cc87 +# without effecting method behaviour +# and adds fallback gem call removed in https://github.com/rails/rails/commit/4c3725723f15fab0a424cb1318b82b460714b72f +require File.join(File.dirname(__FILE__), '../lib/old_rubygems_patch') + Rails::Initializer.run do |config| # Load intial mySociety config diff --git a/lib/old_rubygems_patch.rb b/lib/old_rubygems_patch.rb new file mode 100644 index 000000000..5601a5e90 --- /dev/null +++ b/lib/old_rubygems_patch.rb @@ -0,0 +1,42 @@ +require File.join(File.dirname(__FILE__),'..','vendor','rails','railties','lib','rails','gem_dependency.rb') + +module Rails + class GemDependency < Gem::Dependency + + # This definition of the requirement method is a patch + if !method_defined?(:requirement) + def requirement + req = version_requirements + end + end + + def add_load_paths + self.class.add_frozen_gem_path + return if @loaded || @load_paths_added + if framework_gem? + @load_paths_added = @loaded = @frozen = true + return + end + + begin + dep = Gem::Dependency.new(name, requirement) + spec = Gem.source_index.find { |_,s| s.satisfies_requirement?(dep) }.last + spec.activate # a way that exists + rescue + begin + gem self.name, self.requirement # < 1.8 unhappy way + # This second rescue is a patch - fall back to passing Rails::GemDependency to gem + # for older rubygems + rescue ArgumentError + gem self + end + end + + @spec = Gem.loaded_specs[name] + @frozen = @spec.loaded_from.include?(self.class.unpacked_path) if @spec + @load_paths_added = true + rescue Gem::LoadError + end + end + +end |