Skip to content

Commit 7927ca9

Browse files
eregonansalond
authored andcommitted
Improve documentation regarding loading did_you_mean and registering it as a gem
(cherry picked from commit 0ac7a7e)
1 parent 4c2c562 commit 7927ca9

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

lib/patches/rubygems.rb

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,21 @@
1212
Gem::GemDirsVerification.verify(Gem.path)
1313
Gem::GemDirsVerification.install_hook
1414

15-
# Because did_you_mean was required directly without RubyGems.
16-
# did_you_mean is only required if --disable-gems was not passed.
15+
# We register did_you_mean only here because it was required directly
16+
# without RubyGems in post-boot.rb.
17+
18+
# did_you_mean is only registered as a gem if --disable-gems was not passed, as
19+
# --disable-gems implies --disable-did-you-mean on MRI, i.e.,
20+
# MRI raises NameError for `ruby --disable-gems -e DidYouMean.formatter`.
1721
if Truffle::Boot.get_option 'did_you_mean' and Truffle::Boot.get_option 'rubygems'
1822
begin
1923
gem 'did_you_mean'
2024
rescue LoadError
2125
# Ignore, this happens when GEM_HOME and GEM_PATH are set and do not include
22-
# the default gem home. In such a case, did_you_mean was loaded already, but
23-
# it is no longer possible to register the Gem with RubyGems. This happens
24-
# for instance with 'bundle exec' after `bundle install --deployment`.
26+
# the default gem home. In such a case, despite did_you_mean having been
27+
# loaded already during post-boot.rb, it is no longer possible to register
28+
# the gem with RubyGems. This happens for instance with 'bundle exec' after
29+
# `bundle install --deployment`.
2530
nil
2631
end
2732
end

src/main/ruby/post-boot/post-boot.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
Truffle::Debug.log_warning "#{File.basename(__FILE__)}:#{__LINE__} #{e.message}"
5252
else
5353
if Truffle::Boot.get_option 'did_you_mean'
54+
# Load DidYouMean here manually, to avoid loading RubyGems eagerly
5455
Truffle::Boot.print_time_metric :'before-did-you-mean'
5556
begin
5657
$LOAD_PATH << "#{Truffle::Boot.ruby_home}/lib/ruby/gems/#{Truffle::RUBY_BASE_VERSION}/gems/did_you_mean-1.1.0/lib"

0 commit comments

Comments
 (0)