method
replace_gem
v2_6_3 -
Show latest stable
- Class:
Bundler::RubygemsIntegration
replace_gem(specs, specs_by_name)public
No documentation available.
# File lib/bundler/rubygems_integration.rb, line 370
def replace_gem(specs, specs_by_name)
reverse_rubygems_kernel_mixin
executables = nil
kernel = (class << ::Kernel; self; end)
[kernel, ::Kernel].each do |kernel_class|
redefine_method(kernel_class, :gem) do |dep, *reqs|
executables ||= specs.map(&:executables).flatten if ::Bundler.rubygems.binstubs_call_gem?
if executables && executables.include?(File.basename(caller.first.split(":").first))
break
end
reqs.pop if reqs.last.is_a?(Hash)
unless dep.respond_to?(:name) && dep.respond_to?(:requirement)
dep = Gem::Dependency.new(dep, reqs)
end
if spec = specs_by_name[dep.name]
return true if dep.matches_spec?(spec)
end
message = if spec.nil?
"#{dep.name} is not part of the bundle." " Add it to your #{Bundler.default_gemfile.basename}."
else
"can't activate #{dep}, already activated #{spec.full_name}. " "Make sure all dependencies are added to Gemfile."
end
e = Gem::LoadError.new(message)
e.name = dep.name
if e.respond_to?(:requirement=)
e.requirement = dep.requirement
elsif e.respond_to?(:version_requirement=)
e.version_requirement = dep.requirement
end
raise e
end
# backwards compatibility shim, see https://github.com/bundler/bundler/issues/5102
kernel_class.send(:public, :gem) if Bundler.feature_flag.setup_makes_kernel_gem_public?
end
end