lib/bundler/rubygems_integration.rb in bundler-1.1.pre.4 vs lib/bundler/rubygems_integration.rb in bundler-1.1.pre.5

- old
+ new

@@ -44,11 +44,11 @@ def sources Gem.sources end def gem_dir - Gem.dir.to_s + Gem.dir end def gem_bindir Gem.bindir end @@ -56,13 +56,11 @@ def user_home Gem.user_home end def gem_path - # Make sure that Gem.path is an array of Strings, not some - # internal Rubygems object - Gem.path.map { |x| x.to_s } + Gem.path end def marshal_spec_dir Gem::MARSHAL_SPEC_DIR end @@ -73,10 +71,15 @@ def bin_path(gem, bin, ver) Gem.bin_path(gem, bin, ver) end + def preserve_paths + # this is a no-op outside of Rubygems 1.8 + yield + end + def ui=(obj) Gem::DefaultUserInteraction.ui = obj end def fetch_specs(all, pre, &blk) @@ -118,11 +121,11 @@ ::Kernel.send(:define_method, :gem) do |dep, *reqs| if executables.include? File.basename(caller.first.split(':').first) return end - opts = reqs.last.is_a?(Hash) ? reqs.pop : {} + reqs.pop if reqs.last.is_a?(Hash) unless dep.respond_to?(:name) && dep.respond_to?(:requirement) dep = Gem::Dependency.new(dep, reqs) end @@ -152,10 +155,20 @@ true end end + if defined? ::Deprecate + Deprecate = ::Deprecate + elsif defined? Gem::Deprecate + Deprecate = Gem::Deprecate + else + class Deprecate + def skip_during; yield; end + end + end + def stub_source_index137(specs) # Rubygems versions lower than 1.7 use SourceIndex#from_gems_in source_index_class = (class << Gem::SourceIndex ; self ; end) source_index_class.send(:remove_method, :from_gems_in) source_index_class.send(:define_method, :from_gems_in) do |*args| @@ -167,12 +180,23 @@ end def stub_source_index170(specs) Gem::SourceIndex.send(:define_method, :initialize) do |*args| @gems = {} - self.spec_dirs = *args - add_specs(*specs) + # You're looking at this thinking: Oh! This is how I make those + # rubygems deprecations go away! + # + # You'd be correct BUT using of this method in production code + # must be approved by the rubygems team itself! + # + # This is your warning. If you use this and don't have approval + # we can't protect you. + # + Deprecate.skip_during do + self.spec_dirs = *args + add_specs(*specs) + end end end # Used to make bin stubs that are not created by bundler work # under bundler. The new Gem.bin_path only considers gems in @@ -224,59 +248,73 @@ replace_refresh Gem.clear_paths end - class Modern < RubygemsIntegration + # Rubygems versions 1.3.6 through 1.6.2 + class Legacy < RubygemsIntegration def stub_rubygems(specs) - Gem::Specification.all = specs - - Gem.post_reset { - Gem::Specification.all = specs - } - - stub_source_index170(specs) + stub_source_index137(specs) end def all_specs - Gem::Specification.to_a + Gem.source_index.gems.values end def find_name(name) - Gem::Specification.find_all_by_name name + Gem.source_index.find_name(name) end + end + # Rubygems 1.7 + class Transitional < Legacy + def stub_rubygems(specs) + stub_source_index170(specs) + end end - class Legacy < RubygemsIntegration + # Rubygems 1.8.5 + class Modern < RubygemsIntegration def stub_rubygems(specs) - stub_source_index137(specs) + Gem::Specification.all = specs + + Gem.post_reset { + Gem::Specification.all = specs + } + + stub_source_index170(specs) end def all_specs - Gem.source_index.all_gems.values + Gem::Specification.to_a end def find_name(name) - Gem.source_index.find_name(name) + Gem::Specification.find_all_by_name name end end - class Transitional < Legacy - def stub_rubygems(specs) - stub_source_index170(specs) + # Rubygems 1.8.0 to 1.8.4 + class AlmostModern < Modern + # Rubygems [>= 1.8.0, < 1.8.5] has a bug that changes Gem.dir whenever + # you call Gem::Installer#install with an :install_dir set. We have to + # change it back for our sudo mode to work. + def preserve_paths + old_dir, old_path = gem_dir, gem_path + yield + Gem.use_paths(old_dir, old_path) end end end - if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.7.0') - if Gem::Specification.respond_to? :all= - @rubygems = RubygemsIntegration::Modern.new - else - @rubygems = RubygemsIntegration::Transitional.new - end - else + if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.8.5') + @rubygems = RubygemsIntegration::Modern.new + elsif Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.8.0') + @rubygems = RubygemsIntegration::AlmostModern.new + elsif Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.7.0') + @rubygems = RubygemsIntegration::Transitional.new + else # Rubygems 1.3.6 through 1.6.2 @rubygems = RubygemsIntegration::Legacy.new end class << self attr_reader :rubygems