File tree Expand file tree Collapse file tree 2 files changed +38
-1
lines changed
Expand file tree Collapse file tree 2 files changed +38
-1
lines changed Original file line number Diff line number Diff 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
221253end
222254
223255# for RubyGems without Bundler environment.
Original file line number Diff line number Diff line change 11class 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
You can’t perform that action at this time.
0 commit comments