diff options
Diffstat (limited to 'lib/bundler/installer/standalone.rb')
-rw-r--r-- | lib/bundler/installer/standalone.rb | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/lib/bundler/installer/standalone.rb b/lib/bundler/installer/standalone.rb index 2a8c9a432d..5331df2e95 100644 --- a/lib/bundler/installer/standalone.rb +++ b/lib/bundler/installer/standalone.rb @@ -12,6 +12,7 @@ module Bundler end File.open File.join(bundler_path, "setup.rb"), "w" do |file| file.puts "require 'rbconfig'" + file.puts prevent_gem_activation file.puts define_path_helpers file.puts reverse_rubygems_kernel_mixin paths.each do |path| @@ -55,13 +56,26 @@ module Bundler if spec.source.instance_of?(Source::Path) && spec.source.path.absolute? full_path else - Pathname.new(full_path).relative_path_from(Bundler.root.join(bundler_path)).to_s + SharedHelpers.relative_path_to(full_path, from: Bundler.root.join(bundler_path)) end rescue TypeError error_message = "#{spec.name} #{spec.version} has an invalid gemspec" raise Gem::InvalidSpecificationException.new(error_message) end + def prevent_gem_activation + <<~'END' + module Kernel + remove_method(:gem) if private_method_defined?(:gem) + + def gem(*) + end + + private :gem + end + END + end + def define_path_helpers <<~'END' unless defined?(Gem) @@ -87,8 +101,7 @@ module Bundler if Gem.respond_to?(:discover_gems_on_require=) Gem.discover_gems_on_require = false else - kernel = (class << ::Kernel; self; end) - [kernel, ::Kernel].each do |k| + [::Kernel.singleton_class, ::Kernel].each do |k| if k.private_method_defined?(:gem_original_require) private_require = k.private_method_defined?(:require) k.send(:remove_method, :require) |