aboutsummaryrefslogtreecommitdiffstats
path: root/lib/did_you_mean/core_ext
diff options
context:
space:
mode:
authorKevin Deisz <kevin.deisz@gmail.com>2019-10-29 10:08:37 -0400
committerYuki Nishijima <yk.nishijima@gmail.com>2019-11-30 21:08:19 -0500
commit171803d5d34feb1b4244ca81b9db0a7bc2171c85 (patch)
tree664ee644da144f28152097fbe5ea43329bfc0576 /lib/did_you_mean/core_ext
parenta2fc6a51dd2e1a153559038795e1e2509f9c6a94 (diff)
downloadruby-171803d5d34feb1b4244ca81b9db0a7bc2171c85.tar.gz
Promote did_you_mean to default gem
At the moment, there are some problems with regard to bundler + did_you_mean because of did_you_mean being a bundled gem. Since the vendored version of thor inside bundler and ruby itself explicitly requires did_you_mean, it can become difficult to load it when using Bundler.setup. See this issue: https://github.com/yuki24/did_you_mean/issues/117#issuecomment-482733159 for more details.
Diffstat (limited to 'lib/did_you_mean/core_ext')
-rw-r--r--lib/did_you_mean/core_ext/name_error.rb25
1 files changed, 25 insertions, 0 deletions
diff --git a/lib/did_you_mean/core_ext/name_error.rb b/lib/did_you_mean/core_ext/name_error.rb
new file mode 100644
index 0000000000..77dcd520c0
--- /dev/null
+++ b/lib/did_you_mean/core_ext/name_error.rb
@@ -0,0 +1,25 @@
+module DidYouMean
+ module Correctable
+ def original_message
+ method(:to_s).super_method.call
+ end
+
+ def to_s
+ msg = super.dup
+ suggestion = DidYouMean.formatter.message_for(corrections)
+
+ msg << suggestion if !msg.end_with?(suggestion)
+ msg
+ rescue
+ super
+ end
+
+ def corrections
+ @corrections ||= spell_checker.corrections
+ end
+
+ def spell_checker
+ SPELL_CHECKERS[self.class.to_s].new(self)
+ end
+ end
+end