diff options
author | Yuki Nishijima <yk.nishijima@gmail.com> | 2021-12-21 22:09:33 +0900 |
---|---|---|
committer | Yuki Nishijima <yk.nishijima@gmail.com> | 2021-12-21 22:10:03 +0900 |
commit | cdb7d699d0641e8f081d590d06d07887ac09961f (patch) | |
tree | 0c3db45b8511c5d0815e0ddd5d549fc720fccd50 /lib/did_you_mean.rb | |
parent | 4560091b1c99ab33db0d653b9dd2d977fe4676d5 (diff) |
Revert commits for did_you_mean
This reverts commit 4560091b1c99ab33db0d653b9dd2d977fe4676d5.
This reverts commit a6f76122a2395bd914daa0aa04fb5a6ce4e0c045.
This reverts commit e59b18a6379c55f15ccda85c27d6997d44ef5293.
This reverts commit 505dfae05d56d844ea150676edb87850a406d071.
Diffstat (limited to 'lib/did_you_mean.rb')
-rw-r--r-- | lib/did_you_mean.rb | 53 |
1 files changed, 6 insertions, 47 deletions
diff --git a/lib/did_you_mean.rb b/lib/did_you_mean.rb index 9a77c8ebe7..6d3a6e8bda 100644 --- a/lib/did_you_mean.rb +++ b/lib/did_you_mean.rb @@ -86,24 +86,11 @@ 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.name => spell_checker } - new_mapping.default = NullChecker - - @spell_checkers = Ractor.make_shareable(new_mapping) - else - spell_checkers[error_class.name] = spell_checker - end - + SPELL_CHECKERS[error_class.name] = spell_checker error_class.prepend(Correctable) unless error_class < Correctable end @@ -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?(Reactor) - 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?(Reactor) - Ractor.current[:__did_you_mean_formatter__] = formatter - end + @formatter = formatter end + + @formatter = Formatter.new end |