Added force_activate feature again

This commit is contained in:
Hiroshi SHIBATA 2024-11-13 16:56:11 +09:00
parent 68095ffc16
commit be1d0fcdb0
Notes: git 2025-01-24 06:47:05 +00:00
2 changed files with 38 additions and 1 deletions

View File

@ -218,6 +218,38 @@ module Gem::BUNDLED_GEMS # :nodoc:
msg
end
def self.force_activate(gem)
Bundler.reset!
builder = Bundler::Dsl.new
if Bundler.definition.gemfiles.empty? # bundler/inline
Bundler.definition.locked_gems.specs.each{|spec| builder.gem spec.name, spec.version.to_s }
else
Bundler.definition.gemfiles.each{|gemfile| builder.eval_gemfile(gemfile) }
end
builder.gem gem
definition = builder.to_definition(nil, true)
definition.validate_runtime!
begin
orig_ui = Bundler.ui
orig_no_lock = Bundler::Definition.no_lock
ui = Bundler::UI::Shell.new
ui.level = "silent"
Bundler.ui = ui
Bundler::Definition.no_lock = true
Bundler::Runtime.new(nil, definition).setup
rescue Bundler::GemNotFound
warn "Failed to activate #{gem}, please install it with 'gem install #{gem}'"
ensure
Bundler.ui = orig_ui
Bundler::Definition.no_lock = orig_no_lock
end
end
end
# for RubyGems without Bundler environment.

View File

@ -1,7 +1,12 @@
class Binding
# :nodoc:
def irb
require 'irb'
begin
require 'irb'
rescue LoadError, Gem::LoadError
Gem::BUNDLED_GEMS.force_activate 'irb'
retry
end
irb
end