Skip to content

Commit be1d0fc

Browse files
committed
Added force_activate feature again
1 parent 68095ff commit be1d0fc

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

lib/bundled_gems.rb

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,38 @@ def self.build_message(gem)
218218

219219
msg
220220
end
221+
222+
def self.force_activate(gem)
223+
Bundler.reset!
224+
225+
builder = Bundler::Dsl.new
226+
if Bundler.definition.gemfiles.empty? # bundler/inline
227+
Bundler.definition.locked_gems.specs.each{|spec| builder.gem spec.name, spec.version.to_s }
228+
else
229+
Bundler.definition.gemfiles.each{|gemfile| builder.eval_gemfile(gemfile) }
230+
end
231+
builder.gem gem
232+
233+
definition = builder.to_definition(nil, true)
234+
definition.validate_runtime!
235+
236+
begin
237+
orig_ui = Bundler.ui
238+
orig_no_lock = Bundler::Definition.no_lock
239+
240+
ui = Bundler::UI::Shell.new
241+
ui.level = "silent"
242+
Bundler.ui = ui
243+
Bundler::Definition.no_lock = true
244+
245+
Bundler::Runtime.new(nil, definition).setup
246+
rescue Bundler::GemNotFound
247+
warn "Failed to activate #{gem}, please install it with 'gem install #{gem}'"
248+
ensure
249+
Bundler.ui = orig_ui
250+
Bundler::Definition.no_lock = orig_no_lock
251+
end
252+
end
221253
end
222254

223255
# for RubyGems without Bundler environment.

prelude.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
class Binding
22
# :nodoc:
33
def irb
4-
require 'irb'
4+
begin
5+
require 'irb'
6+
rescue LoadError, Gem::LoadError
7+
Gem::BUNDLED_GEMS.force_activate 'irb'
8+
retry
9+
end
510
irb
611
end
712

0 commit comments

Comments
 (0)