[ruby/irb] Discover and load debug.gem even if it's not in Gemfile
(https://github.com/ruby/irb/pull/448) * Minor fixes on debug command * Discover and load debug.gem even if it's not in Gemfile * Eliminate else for rescue * Discover the latest one from all gem paths
This commit is contained in:
parent
b1cbc883f2
commit
ba3b40a9ae
@ -48,8 +48,8 @@ module IRB
|
||||
unless defined?(DEBUGGER__::SESSION)
|
||||
begin
|
||||
require "debug/session"
|
||||
rescue LoadError
|
||||
return false
|
||||
rescue LoadError # debug.gem is not written in Gemfile
|
||||
return false unless load_bundled_debug_gem
|
||||
end
|
||||
DEBUGGER__.start(nonstop: true)
|
||||
end
|
||||
@ -68,6 +68,29 @@ module IRB
|
||||
|
||||
true
|
||||
end
|
||||
|
||||
# This is used when debug.gem is not written in Gemfile. Even if it's not
|
||||
# installed by `bundle install`, debug.gem is installed by default because
|
||||
# it's a bundled gem. This method tries to activate and load that.
|
||||
def load_bundled_debug_gem
|
||||
# Discover latest debug.gem under GEM_PATH
|
||||
debug_gem = Gem.paths.path.map { |path| Dir.glob("#{path}/gems/debug-*") }.flatten.select do |path|
|
||||
File.basename(path).match?(/\Adebug-\d+\.\d+\.\d+\z/)
|
||||
end.sort_by do |path|
|
||||
Gem::Version.new(File.basename(path).delete_prefix('debug-'))
|
||||
end.last
|
||||
return false unless debug_gem
|
||||
|
||||
# Attempt to forcibly load the bundled gem
|
||||
$LOAD_PATH << "#{debug_gem}/lib"
|
||||
begin
|
||||
require "debug/session"
|
||||
puts "Loaded #{File.basename(debug_gem)}"
|
||||
true
|
||||
rescue LoadError
|
||||
false
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user