summaryrefslogtreecommitdiff
path: root/lib/did_you_mean.rb
diff options
context:
space:
mode:
authorYuki Nishijima <yk.nishijima@gmail.com>2021-12-23 10:08:07 +0900
committerYuki Nishijima <yk.nishijima@gmail.com>2021-12-23 10:09:10 +0900
commitde841e2e28a8f721895acb1a76c7847b40cc487a (patch)
tree26bf60748de9eb252b97ca5c7aab3927473a5c59 /lib/did_you_mean.rb
parentc529014b9dc107c2b938f87e13941b6709fc7a76 (diff)
downloadruby-de841e2e28a8f721895acb1a76c7847b40cc487a.tar.gz
Revert the commits for did_you_mean
This reverts commit feaf4fbc3fa16382fbd07158c448c7b5bdae78b5. This reverts commit 0d4bfbdbe1f880c712b3e60de5fce423e6096f8d. This reverts commit ac4e0978ee4358430396403065eabe1aca05784f.
Diffstat (limited to 'lib/did_you_mean.rb')
-rw-r--r--lib/did_you_mean.rb55
1 files changed, 7 insertions, 48 deletions
diff --git a/lib/did_you_mean.rb b/lib/did_you_mean.rb
index 2df238da06..6d3a6e8bda 100644
--- a/lib/did_you_mean.rb
+++ b/lib/did_you_mean.rb
@@ -86,25 +86,12 @@ require_relative 'did_you_mean/tree_spell_checker'
#
module DidYouMean
# Map of error types and spell checker objects.
- @spell_checkers = Hash.new(NullChecker)
-
- # Returns a sharable hash map of error types and spell checker objects.
- def self.spell_checkers
- @spell_checkers
- end
+ SPELL_CHECKERS = Hash.new(NullChecker)
# Adds +DidYouMean+ functionality to an error using a given spell checker
def self.correct_error(error_class, spell_checker)
- if defined?(Ractor)
- new_mapping = { **@spell_checkers, error_class.to_s => spell_checker }
- new_mapping.default = NullChecker
-
- @spell_checkers = Ractor.make_shareable(new_mapping)
- else
- spell_checkers[error_class.to_s] = spell_checker
- end
-
- error_class.prepend(Correctable) if error_class.is_a?(Class) && !(error_class < Correctable)
+ SPELL_CHECKERS[error_class.name] = spell_checker
+ error_class.prepend(Correctable) unless error_class < Correctable
end
correct_error NameError, NameErrorCheckers
@@ -113,43 +100,15 @@ module DidYouMean
correct_error LoadError, RequirePathChecker if RUBY_VERSION >= '2.8.0'
correct_error NoMatchingPatternKeyError, PatternKeyNameChecker if defined?(::NoMatchingPatternKeyError)
- # TODO: Remove on 3.3:
- class DeprecatedMapping # :nodoc:
- def []=(key, value)
- warn "Calling `DidYouMean::SPELL_CHECKERS[#{key.to_s}] = #{value.to_s}' has been deprecated. " \
- "Please call `DidYouMean.correct_error(#{key.to_s}, #{value.to_s})' instead."
-
- DidYouMean.correct_error(key, value)
- end
-
- def merge!(hash)
- warn "Calling `DidYouMean::SPELL_CHECKERS.merge!(error_name => spell_checker)' has been deprecated. " \
- "Please call `DidYouMean.correct_error(error_name, spell_checker)' instead."
-
- hash.each do |error_class, spell_checker|
- DidYouMean.correct_error(error_class, spell_checker)
- end
- end
- end
-
- # TODO: Remove on 3.3:
- SPELL_CHECKERS = DeprecatedMapping.new
- deprecate_constant :SPELL_CHECKERS
- private_constant :DeprecatedMapping
-
# Returns the currently set formatter. By default, it is set to +DidYouMean::Formatter+.
def self.formatter
- if defined?(Ractor)
- Ractor.current[:__did_you_mean_formatter__] || Formatter
- else
- Formatter
- end
+ @formatter
end
# Updates the primary formatter used to format the suggestions.
def self.formatter=(formatter)
- if defined?(Ractor)
- Ractor.current[:__did_you_mean_formatter__] = formatter
- end
+ @formatter = formatter
end
+
+ @formatter = Formatter.new
end