Skip to content

Commit

Permalink
* gems/default_gems: Make the SPELL_CHECKERS constant as compatible a…
Browse files Browse the repository at this point in the history
…s possible
  • Loading branch information
yuki24 committed Dec 21, 2021
1 parent a6f7612 commit 4560091
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion lib/did_you_mean.rb
Expand Up @@ -114,8 +114,28 @@ def self.correct_error(error_class, spell_checker)
correct_error NoMatchingPatternKeyError, PatternKeyNameChecker if defined?(::NoMatchingPatternKeyError)

# TODO: Remove on 3.3:
SPELL_CHECKERS = @spell_checkers
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
Expand Down

0 comments on commit 4560091

Please sign in to comment.