aboutsummaryrefslogtreecommitdiffstats
path: root/railties/lib/rails/command/spellchecker.rb
diff options
context:
space:
mode:
Diffstat (limited to 'railties/lib/rails/command/spellchecker.rb')
-rw-r--r--railties/lib/rails/command/spellchecker.rb9
1 files changed, 7 insertions, 2 deletions
diff --git a/railties/lib/rails/command/spellchecker.rb b/railties/lib/rails/command/spellchecker.rb
index 59ccab4ea2..04485097fa 100644
--- a/railties/lib/rails/command/spellchecker.rb
+++ b/railties/lib/rails/command/spellchecker.rb
@@ -4,11 +4,16 @@ module Rails
module Command
module Spellchecker # :nodoc:
class << self
- def suggest(word, from:, count: 3)
- from.sort_by { |w| levenshtein_distance(word, w) }.take(count)
+ def suggest(word, from:)
+ if defined?(DidYouMean::SpellChecker)
+ DidYouMean::SpellChecker.new(dictionary: from.map(&:to_s)).correct(word).first
+ else
+ from.sort_by { |w| levenshtein_distance(word, w) }.first
+ end
end
private
+
# This code is based directly on the Text gem implementation.
# Copyright (c) 2006-2013 Paul Battley, Michael Neumann, Tim Fletcher.
#