Skip to content

Commit 8c57f1d

Browse files
authored
Do not require did_you_mean
This caused a drastic performance hit (100x slower) on our JRuby applications because it was requiring `did_you_mean` even though we have: ``` JRUBY_OPTS="--disable:did_you_mean" ``` set. In looking through other libraries that use `did_you_mean`, it looks like a fairly common pattern is to just check if the portions of `did_you_mean` that are needed are defined. I tried to replicate that in this patch.
1 parent 4344761 commit 8c57f1d

File tree

1 file changed

+14
-18
lines changed

1 file changed

+14
-18
lines changed

lib/thor/error.rb

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,18 @@
11
class Thor
2-
Correctable =
3-
begin
4-
require 'did_you_mean'
5-
6-
# In order to support versions of Ruby that don't have keyword
7-
# arguments, we need our own spell checker class that doesn't take key
8-
# words. Even though this code wouldn't be hit because of the check
9-
# above, it's still necessary because the interpreter would otherwise be
10-
# unable to parse the file.
11-
class NoKwargSpellChecker < DidYouMean::SpellChecker # :nodoc:
12-
def initialize(dictionary)
13-
@dictionary = dictionary
14-
end
15-
end
16-
17-
DidYouMean::Correctable
18-
rescue LoadError, NameError
19-
end
2+
Correctable = if defined?(DidYouMean::SpellChecker) && defined?(DidYouMean::Correctable)
3+
# In order to support versions of Ruby that don't have keyword
4+
# arguments, we need our own spell checker class that doesn't take key
5+
# words. Even though this code wouldn't be hit because of the check
6+
# above, it's still necessary because the interpreter would otherwise be
7+
# unable to parse the file.
8+
class NoKwargSpellChecker < DidYouMean::SpellChecker # :nodoc:
9+
def initialize(dictionary)
10+
@dictionary = dictionary
11+
end
12+
end
13+
14+
DidYouMean::Correctable
15+
end
2016

2117
# Thor::Error is raised when it's caused by wrong usage of thor classes. Those
2218
# errors have their backtrace suppressed and are nicely shown to the user.

0 commit comments

Comments
 (0)