aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNick LaMuro <nicklamuro@gmail.com>2017-10-23 11:11:59 -0500
committerNick LaMuro <nicklamuro@gmail.com>2017-10-28 17:32:32 -0500
commitb2545e4106c8388cb2a4d9e06c31954e5ee2c948 (patch)
treec79b1de9b9e1f140c54fccdadb4755ae7a295310
parenta822fc513cb3c98207a14fc203c973e13f42e306 (diff)
downloadrails-b2545e4106c8388cb2a4d9e06c31954e5ee2c948.tar.gz
rails-b2545e4106c8388cb2a4d9e06c31954e5ee2c948.tar.bz2
rails-b2545e4106c8388cb2a4d9e06c31954e5ee2c948.zip
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.
-rw-r--r--actionpack/test/dispatch/request_test.rb2
-rw-r--r--activesupport/lib/active_support/deprecation/constant_accessor.rb4
-rw-r--r--activesupport/lib/active_support/deprecation/proxy_wrappers.rb3
-rw-r--r--activesupport/lib/active_support/inflector/inflections.rb6
-rw-r--r--activesupport/test/inflector_test.rb6
5 files changed, 15 insertions, 6 deletions
diff --git a/actionpack/test/dispatch/request_test.rb b/actionpack/test/dispatch/request_test.rb
index 2057aecbf9..8661dc56d6 100644
--- a/actionpack/test/dispatch/request_test.rb
+++ b/actionpack/test/dispatch/request_test.rb
@@ -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"
diff --git a/activesupport/lib/active_support/deprecation/constant_accessor.rb b/activesupport/lib/active_support/deprecation/constant_accessor.rb
index 3d7eedf637..dd515cd6f4 100644
--- a/activesupport/lib/active_support/deprecation/constant_accessor.rb
+++ b/activesupport/lib/active_support/deprecation/constant_accessor.rb
@@ -1,7 +1,5 @@
# 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 @@ module ActiveSupport
# ["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)
diff --git a/activesupport/lib/active_support/deprecation/proxy_wrappers.rb b/activesupport/lib/active_support/deprecation/proxy_wrappers.rb
index f6c6648917..782ad2519c 100644
--- a/activesupport/lib/active_support/deprecation/proxy_wrappers.rb
+++ b/activesupport/lib/active_support/deprecation/proxy_wrappers.rb
@@ -1,6 +1,5 @@
# frozen_string_literal: true
-require "active_support/inflector/methods"
require "active_support/core_ext/regexp"
module ActiveSupport
@@ -125,6 +124,8 @@ module ActiveSupport
# ["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
diff --git a/activesupport/lib/active_support/inflector/inflections.rb b/activesupport/lib/active_support/inflector/inflections.rb
index 6cfa8bb5aa..0450a4be4c 100644
--- a/activesupport/lib/active_support/inflector/inflections.rb
+++ b/activesupport/lib/active_support/inflector/inflections.rb
@@ -4,6 +4,7 @@ require "concurrent/map"
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 @@ module ActiveSupport
@__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
diff --git a/activesupport/test/inflector_test.rb b/activesupport/test/inflector_test.rb
index eeec0ab1a5..ad2ec1d67d 100644
--- a/activesupport/test/inflector_test.rb
+++ b/activesupport/test/inflector_test.rb
@@ -224,6 +224,12 @@ class InflectorTest < ActiveSupport::TestCase
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))