[前][次][番号順一覧][スレッド一覧]

ruby-changes:70422

From: Yuki <ko1@a...>
Date: Tue, 21 Dec 2021 22:00:59 +0900 (JST)
Subject: [ruby-changes:70422] 4560091b1c (master): * gems/default_gems: Make the SPELL_CHECKERS constant as compatible as possible

https://git.ruby-lang.org/ruby.git/commit/?id=4560091b1c

From 4560091b1c99ab33db0d653b9dd2d977fe4676d5 Mon Sep 17 00:00:00 2001
From: Yuki Nishijima <yk.nishijima@g...>
Date: Tue, 21 Dec 2021 22:00:23 +0900
Subject: * gems/default_gems: Make the SPELL_CHECKERS constant as compatible
 as possible

---
 lib/did_you_mean.rb | 22 +++++++++++++++++++++-
 1 file changed, 21 insertions(+), 1 deletion(-)

diff --git a/lib/did_you_mean.rb b/lib/did_you_mean.rb
index 0aef3240591..9a77c8ebe7d 100644
--- a/lib/did_you_mean.rb
+++ b/lib/did_you_mean.rb
@@ -114,8 +114,28 @@ module DidYouMean https://github.com/ruby/ruby/blob/trunk/lib/did_you_mean.rb#L114
   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
-- 
cgit v1.2.1


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]