提交 b2545e41 编写于 作者: N Nick LaMuro

Deprecate ActiveSupport::Inflector#acronym_regex

To be removed in Rails 6.0 (default for the deprecate helper).  Code
moved around as well for the ActiveSupport::Deprecation modules, since
it was dependent on ActiveSupport::Inflector being loaded for it to
work.  By "lazy loading" the Inflector code from within the Deprecation
code, we can require ActiveSupport::Deprecation from
ActiveSupport::Inflector and not get a circular dependency issue.
上级 a822fc51
......@@ -763,7 +763,7 @@ class RequestMethod < BaseRequestTest
test "post uneffected by local inflections" do
existing_acronyms = ActiveSupport::Inflector.inflections.acronyms.dup
existing_acronym_regex = ActiveSupport::Inflector.inflections.acronym_regex.dup
assert_deprecated { ActiveSupport::Inflector.inflections.acronym_regex.dup }
begin
ActiveSupport::Inflector.inflections do |inflect|
inflect.acronym "POS"
......
# frozen_string_literal: true
require "active_support/inflector/methods"
module ActiveSupport
class Deprecation
# DeprecatedConstantAccessor transforms a constant into a deprecated one by
......@@ -29,6 +27,8 @@ class Deprecation
# ["Mercury", "Venus", "Earth", "Mars", "Jupiter", "Saturn", "Uranus", "Neptune"]
module DeprecatedConstantAccessor
def self.included(base)
require "active_support/inflector/methods"
extension = Module.new do
def const_missing(missing_const_name)
if class_variable_defined?(:@@_deprecated_constants)
......
# frozen_string_literal: true
require "active_support/inflector/methods"
require "active_support/core_ext/regexp"
module ActiveSupport
......@@ -125,6 +124,8 @@ def warn(callstack, called, args)
# ["Mercury", "Venus", "Earth", "Mars", "Jupiter", "Saturn", "Uranus", "Neptune"]
class DeprecatedConstantProxy < DeprecationProxy
def initialize(old_const, new_const, deprecator = ActiveSupport::Deprecation.instance, message: "#{old_const} is deprecated! Use #{new_const} instead.")
require "active_support/inflector/methods"
@old_const = old_const
@new_const = new_const
@deprecator = deprecator
......
......@@ -4,6 +4,7 @@
require "active_support/core_ext/array/prepend_and_append"
require "active_support/core_ext/regexp"
require "active_support/i18n"
require "active_support/deprecation"
module ActiveSupport
module Inflector
......@@ -66,8 +67,9 @@ def self.instance(locale = :en)
@__instance__[locale] ||= new
end
attr_reader :plurals, :singulars, :uncountables, :humans,
:acronyms, :acronym_regex
attr_reader :plurals, :singulars, :uncountables, :humans, :acronyms, :acronym_regex
deprecate :acronym_regex
attr_reader :acronyms_camelize_regex, :acronyms_underscore_regex # :nodoc:
def initialize
......
......@@ -224,6 +224,12 @@ def test_underscore_acronym_sequence
assert_equal("json_html_api", ActiveSupport::Inflector.underscore("JSONHTMLAPI"))
end
def test_acronym_regexp_is_deprecated
assert_deprecated do
ActiveSupport::Inflector.inflections.acronym_regex
end
end
def test_underscore
CamelToUnderscore.each do |camel, underscore|
assert_equal(underscore, ActiveSupport::Inflector.underscore(camel))
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册