Skip to content

Commit fc2dc7c

Browse files
committed
Remove deprecated support to call the following methods without passing a deprecator
- `deprecate` - `deprecate_constant` - `ActiveSupport::Deprecation::DeprecatedObjectProxy.new` - `ActiveSupport::Deprecation::DeprecatedInstanceVariableProxy.new` - `ActiveSupport::Deprecation::DeprecatedConstantProxy.new` - `assert_deprecated` - `assert_not_deprecated` - `collect_deprecations`
1 parent c682bf2 commit fc2dc7c

File tree

7 files changed

+56
-51
lines changed

7 files changed

+56
-51
lines changed

activesupport/CHANGELOG.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
* Remove deprecated support to call the following methods without passing a deprecator:
2+
3+
- `deprecate`
4+
- `deprecate_constant`
5+
- `ActiveSupport::Deprecation::DeprecatedObjectProxy.new`
6+
- `ActiveSupport::Deprecation::DeprecatedInstanceVariableProxy.new`
7+
- `ActiveSupport::Deprecation::DeprecatedConstantProxy.new`
8+
- `assert_deprecated`
9+
- `assert_not_deprecated`
10+
- `collect_deprecations`
11+
12+
*Rafael Mendonça França*
13+
114
* Remove deprecated `ActiveSupport::Deprecation` delegation to instance.
215

316
*Rafael Mendonça França*

activesupport/lib/active_support/core_ext/module/deprecation.rb

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,12 @@ class Module
1414
# Kernel.warn message
1515
# end
1616
# end
17-
def deprecate(*method_names, deprecator: nil, **options)
17+
def deprecate(*method_names, deprecator:, **options)
1818
if deprecator.is_a?(ActiveSupport::Deprecation)
1919
deprecator.deprecate_methods(self, *method_names, **options)
2020
elsif deprecator
2121
# we just need any instance to call deprecate_methods, but the deprecation will be emitted by deprecator
2222
ActiveSupport.deprecator.deprecate_methods(self, *method_names, **options, deprecator: deprecator)
23-
else
24-
ActiveSupport.deprecator.warn("Module.deprecate without a deprecator is deprecated")
25-
ActiveSupport::Deprecation._instance.deprecate_methods(self, *method_names, **options)
2623
end
2724
end
2825
end

activesupport/lib/active_support/deprecation/constant_accessor.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,7 @@ def const_missing(missing_const_name)
3939
super
4040
end
4141

42-
def deprecate_constant(const_name, new_constant, message: nil, deprecator: nil)
43-
ActiveSupport.deprecator.warn("DeprecatedConstantAccessor.deprecate_constant without a deprecator is deprecated") unless deprecator
44-
deprecator ||= ActiveSupport::Deprecation._instance
42+
def deprecate_constant(const_name, new_constant, deprecator:, message: nil)
4543
class_variable_set(:@@_deprecated_constants, {}) unless class_variable_defined?(:@@_deprecated_constants)
4644
class_variable_get(:@@_deprecated_constants)[const_name.to_s] = { new: new_constant, message: message, deprecator: deprecator }
4745
end

activesupport/lib/active_support/deprecation/proxy_wrappers.rb

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
module ActiveSupport
44
class Deprecation
55
class DeprecationProxy # :nodoc:
6-
def self.new(*args, &block)
6+
def self.new(*args, **kwargs, &block)
77
object = args.first
88

99
return object unless object
@@ -36,11 +36,10 @@ def method_missing(called, *args, &block)
3636
# (Backtrace)
3737
# # => "#<Object:0x007fb9b34c34b0>"
3838
class DeprecatedObjectProxy < DeprecationProxy
39-
def initialize(object, message, deprecator = nil)
39+
def initialize(object, message, deprecator)
4040
@object = object
4141
@message = message
42-
ActiveSupport.deprecator.warn("DeprecatedObjectProxy without a deprecator is deprecated") unless deprecator
43-
@deprecator = deprecator || ActiveSupport::Deprecation._instance
42+
@deprecator = deprecator
4443
end
4544

4645
private
@@ -86,12 +85,11 @@ def warn(callstack, called, args)
8685
# example.request.to_s
8786
# # => "special_request"
8887
class DeprecatedInstanceVariableProxy < DeprecationProxy
89-
def initialize(instance, method, var = "@#{method}", deprecator = nil)
88+
def initialize(instance, method, var = "@#{method}", deprecator:)
9089
@instance = instance
9190
@method = method
9291
@var = var
93-
ActiveSupport.deprecator.warn("DeprecatedInstanceVariableProxy without a deprecator is deprecated") unless deprecator
94-
@deprecator = deprecator || ActiveSupport::Deprecation._instance
92+
@deprecator = deprecator
9593
end
9694

9795
private
@@ -127,13 +125,12 @@ def self.new(*args, **options, &block)
127125
super
128126
end
129127

130-
def initialize(old_const, new_const, deprecator = nil, message: "#{old_const} is deprecated! Use #{new_const} instead.")
128+
def initialize(old_const, new_const, deprecator, message: "#{old_const} is deprecated! Use #{new_const} instead.")
131129
Kernel.require "active_support/inflector/methods"
132130

133131
@old_const = old_const
134132
@new_const = new_const
135-
ActiveSupport.deprecator.warn("DeprecatedConstantProxy without a deprecator is deprecated") unless deprecator
136-
@deprecator = deprecator || ActiveSupport::Deprecation._instance
133+
@deprecator = deprecator
137134
@message = message
138135
end
139136

activesupport/lib/active_support/testing/deprecation.rb

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,11 @@ module Deprecation
2929
# end
3030
def assert_deprecated(match = nil, deprecator = nil, &block)
3131
match, deprecator = nil, match if match.is_a?(ActiveSupport::Deprecation)
32+
3233
unless deprecator
33-
ActiveSupport.deprecator.warn("assert_deprecated without a deprecator is deprecated")
34-
deprecator = ActiveSupport::Deprecation._instance
34+
raise ArgumentError, "No deprecator given"
3535
end
36+
3637
result, warnings = collect_deprecations(deprecator, &block)
3738
assert !warnings.empty?, "Expected a deprecation warning within the block but received none"
3839
if match
@@ -51,11 +52,7 @@ def assert_deprecated(match = nil, deprecator = nil, &block)
5152
# assert_not_deprecated(ActiveSupport::Deprecation.new) do
5253
# CustomDeprecator.warn "message" # passes assertion, different deprecator
5354
# end
54-
def assert_not_deprecated(deprecator = nil, &block)
55-
unless deprecator
56-
ActiveSupport.deprecator.warn("assert_not_deprecated without a deprecator is deprecated")
57-
deprecator = ActiveSupport::Deprecation._instance
58-
end
55+
def assert_not_deprecated(deprecator, &block)
5956
result, deprecations = collect_deprecations(deprecator, &block)
6057
assert deprecations.empty?, "Expected no deprecation warning within the block but received #{deprecations.size}: \n #{deprecations * "\n "}"
6158
result
@@ -69,11 +66,7 @@ def assert_not_deprecated(deprecator = nil, &block)
6966
# ActiveSupport::Deprecation.new.warn "other message"
7067
# :result
7168
# end # => [:result, ["message"]]
72-
def collect_deprecations(deprecator = nil)
73-
unless deprecator
74-
ActiveSupport.deprecator.warn("collect_deprecations without a deprecator is deprecated")
75-
deprecator = ActiveSupport::Deprecation._instance
76-
end
69+
def collect_deprecations(deprecator)
7770
old_behavior = deprecator.behavior
7871
deprecations = []
7972
deprecator.behavior = Proc.new do |message, callstack|

activesupport/test/deprecation_test.rb

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ def setup
4747
end
4848
end
4949

50-
test "assert_deprecated is deprecated without a deprecator" do
51-
assert_deprecated(ActiveSupport.deprecator) do
50+
test "assert_deprecated requires a deprecator" do
51+
assert_raises(ArgumentError) do
5252
assert_deprecated do
5353
ActiveSupport::Deprecation._instance.warn
5454
end
@@ -61,8 +61,8 @@ def setup
6161
end
6262
end
6363

64-
test "assert_not_deprecated is deprecated without a deprecator" do
65-
assert_deprecated(ActiveSupport.deprecator) do
64+
test "assert_not_deprecated requires a deprecator" do
65+
assert_raises(ArgumentError) do
6666
assert_not_deprecated { }
6767
end
6868
end
@@ -77,8 +77,8 @@ def setup
7777
assert_match "DEPRECATION WARNING:", result.last.sole
7878
end
7979

80-
test "collect_deprecations is deprecated without a deprecator" do
81-
assert_deprecated(ActiveSupport.deprecator) do
80+
test "collect_deprecations requires a deprecator" do
81+
assert_raises(ArgumentError) do
8282
collect_deprecations { }
8383
end
8484
end
@@ -116,24 +116,20 @@ def setup
116116
end
117117
end
118118

119-
test "Module::deprecate without a deprecator is deprecated" do
119+
test "Module::deprecate requires a deprecator" do
120120
klass = Class.new(Deprecatee)
121-
_, deprecations = collect_deprecations(ActiveSupport.deprecator) do
121+
assert_raises(ArgumentError) do
122122
klass.deprecate :zero
123123
end
124-
assert_match "Module.deprecate without a deprecator is deprecated", deprecations.sole
125-
assert_deprecated(/zero is deprecated/, ActiveSupport::Deprecation._instance) do
126-
klass.new.zero
127-
end
128124
end
129125

130126
test "DeprecatedObjectProxy" do
131127
deprecated_object = ActiveSupport::Deprecation::DeprecatedObjectProxy.new(Object.new, ":bomb:", @deprecator)
132128
assert_deprecated(/:bomb:/, @deprecator) { deprecated_object.to_s }
133129
end
134130

135-
test "DeprecatedObjectProxy without a deprecator is deprecated" do
136-
assert_deprecated(ActiveSupport.deprecator) do
131+
test "DeprecatedObjectProxy requires a deprecator" do
132+
assert_raises(ArgumentError) do
137133
ActiveSupport::Deprecation::DeprecatedObjectProxy.new(Object.new, ":bomb:")
138134
end
139135
end
@@ -302,7 +298,7 @@ def setup
302298

303299
test "DeprecatedInstanceVariableProxy" do
304300
instance = Deprecatee.new
305-
instance.fubar = ActiveSupport::Deprecation::DeprecatedInstanceVariableProxy.new(instance, :foo_bar, "@fubar", @deprecator)
301+
instance.fubar = ActiveSupport::Deprecation::DeprecatedInstanceVariableProxy.new(instance, :foo_bar, "@fubar", deprecator: @deprecator)
306302
instance.foo_bar = "foo bar!"
307303

308304
fubar_size = assert_deprecated("@fubar.size", @deprecator) { instance.fubar.size }
@@ -314,15 +310,15 @@ def setup
314310

315311
test "DeprecatedInstanceVariableProxy does not warn on inspect" do
316312
instance = Deprecatee.new
317-
instance.fubar = ActiveSupport::Deprecation::DeprecatedInstanceVariableProxy.new(instance, :foo_bar, "@fubar", @deprecator)
313+
instance.fubar = ActiveSupport::Deprecation::DeprecatedInstanceVariableProxy.new(instance, :foo_bar, "@fubar", deprecator: @deprecator)
318314
instance.foo_bar = "foo bar!"
319315

320316
fubar_inspected = assert_not_deprecated(@deprecator) { instance.fubar.inspect }
321317
assert_equal instance.foo_bar.inspect, fubar_inspected
322318
end
323319

324-
test "DeprecatedInstanceVariableProxy without a deprecator is deprecated" do
325-
assert_deprecated(ActiveSupport.deprecator) do
320+
test "DeprecatedInstanceVariableProxy requires a deprecator" do
321+
assert_raises(ArgumentError) do
326322
ActiveSupport::Deprecation::DeprecatedInstanceVariableProxy.new(Deprecatee.new, :foobar, "@fubar")
327323
end
328324
end
@@ -354,8 +350,8 @@ def setup
354350
end
355351
end
356352

357-
test "DeprecatedConstantProxy without a deprecator is deprecated" do
358-
assert_deprecated(ActiveSupport.deprecator) do
353+
test "DeprecatedConstantProxy requires a deprecator" do
354+
assert_raise(ArgumentError) do
359355
ActiveSupport::Deprecation::DeprecatedConstantProxy.new("Fuu", "Undeprecated::Foo")
360356
end
361357
end
@@ -383,9 +379,9 @@ def setup
383379
end
384380
end
385381

386-
test "deprecate_constant is deprecated without a deprecator" do
382+
test "deprecate_constant requires a deprecator" do
387383
legacy = Module.new.include(ActiveSupport::Deprecation::DeprecatedConstantAccessor)
388-
assert_deprecated("DeprecatedConstantAccessor.deprecate_constant without a deprecator is deprecated", ActiveSupport.deprecator) do
384+
assert_raises(ArgumentError) do
389385
legacy.deprecate_constant "OLD", "NEW"
390386
end
391387
end

guides/source/7_2_release_notes.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,17 @@ Please refer to the [Changelog][active-support] for detailed changes.
207207

208208
### Removals
209209

210+
* Remove deprecated support to call the following methods without passing a deprecator:
211+
212+
- `deprecate`
213+
- `deprecate_constant`
214+
- `ActiveSupport::Deprecation::DeprecatedObjectProxy.new`
215+
- `ActiveSupport::Deprecation::DeprecatedInstanceVariableProxy.new`
216+
- `ActiveSupport::Deprecation::DeprecatedConstantProxy.new`
217+
- `assert_deprecated`
218+
- `assert_not_deprecated`
219+
- `collect_deprecations`
220+
210221
* Remove deprecated `ActiveSupport::Deprecation` delegation to instance.
211222

212223
* Remove deprecated `SafeBuffer#clone_empty`.

0 commit comments

Comments
 (0)