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`
This commit is contained in:
parent
c682bf2641
commit
fc2dc7c8d3
@ -1,3 +1,16 @@
|
||||
* 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`
|
||||
|
||||
*Rafael Mendonça França*
|
||||
|
||||
* Remove deprecated `ActiveSupport::Deprecation` delegation to instance.
|
||||
|
||||
*Rafael Mendonça França*
|
||||
|
@ -14,15 +14,12 @@ class Module
|
||||
# Kernel.warn message
|
||||
# end
|
||||
# end
|
||||
def deprecate(*method_names, deprecator: nil, **options)
|
||||
def deprecate(*method_names, deprecator:, **options)
|
||||
if deprecator.is_a?(ActiveSupport::Deprecation)
|
||||
deprecator.deprecate_methods(self, *method_names, **options)
|
||||
elsif deprecator
|
||||
# we just need any instance to call deprecate_methods, but the deprecation will be emitted by deprecator
|
||||
ActiveSupport.deprecator.deprecate_methods(self, *method_names, **options, deprecator: deprecator)
|
||||
else
|
||||
ActiveSupport.deprecator.warn("Module.deprecate without a deprecator is deprecated")
|
||||
ActiveSupport::Deprecation._instance.deprecate_methods(self, *method_names, **options)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -39,9 +39,7 @@ def const_missing(missing_const_name)
|
||||
super
|
||||
end
|
||||
|
||||
def deprecate_constant(const_name, new_constant, message: nil, deprecator: nil)
|
||||
ActiveSupport.deprecator.warn("DeprecatedConstantAccessor.deprecate_constant without a deprecator is deprecated") unless deprecator
|
||||
deprecator ||= ActiveSupport::Deprecation._instance
|
||||
def deprecate_constant(const_name, new_constant, deprecator:, message: nil)
|
||||
class_variable_set(:@@_deprecated_constants, {}) unless class_variable_defined?(:@@_deprecated_constants)
|
||||
class_variable_get(:@@_deprecated_constants)[const_name.to_s] = { new: new_constant, message: message, deprecator: deprecator }
|
||||
end
|
||||
|
@ -3,7 +3,7 @@
|
||||
module ActiveSupport
|
||||
class Deprecation
|
||||
class DeprecationProxy # :nodoc:
|
||||
def self.new(*args, &block)
|
||||
def self.new(*args, **kwargs, &block)
|
||||
object = args.first
|
||||
|
||||
return object unless object
|
||||
@ -36,11 +36,10 @@ def method_missing(called, *args, &block)
|
||||
# (Backtrace)
|
||||
# # => "#<Object:0x007fb9b34c34b0>"
|
||||
class DeprecatedObjectProxy < DeprecationProxy
|
||||
def initialize(object, message, deprecator = nil)
|
||||
def initialize(object, message, deprecator)
|
||||
@object = object
|
||||
@message = message
|
||||
ActiveSupport.deprecator.warn("DeprecatedObjectProxy without a deprecator is deprecated") unless deprecator
|
||||
@deprecator = deprecator || ActiveSupport::Deprecation._instance
|
||||
@deprecator = deprecator
|
||||
end
|
||||
|
||||
private
|
||||
@ -86,12 +85,11 @@ def warn(callstack, called, args)
|
||||
# example.request.to_s
|
||||
# # => "special_request"
|
||||
class DeprecatedInstanceVariableProxy < DeprecationProxy
|
||||
def initialize(instance, method, var = "@#{method}", deprecator = nil)
|
||||
def initialize(instance, method, var = "@#{method}", deprecator:)
|
||||
@instance = instance
|
||||
@method = method
|
||||
@var = var
|
||||
ActiveSupport.deprecator.warn("DeprecatedInstanceVariableProxy without a deprecator is deprecated") unless deprecator
|
||||
@deprecator = deprecator || ActiveSupport::Deprecation._instance
|
||||
@deprecator = deprecator
|
||||
end
|
||||
|
||||
private
|
||||
@ -127,13 +125,12 @@ def self.new(*args, **options, &block)
|
||||
super
|
||||
end
|
||||
|
||||
def initialize(old_const, new_const, deprecator = nil, message: "#{old_const} is deprecated! Use #{new_const} instead.")
|
||||
def initialize(old_const, new_const, deprecator, message: "#{old_const} is deprecated! Use #{new_const} instead.")
|
||||
Kernel.require "active_support/inflector/methods"
|
||||
|
||||
@old_const = old_const
|
||||
@new_const = new_const
|
||||
ActiveSupport.deprecator.warn("DeprecatedConstantProxy without a deprecator is deprecated") unless deprecator
|
||||
@deprecator = deprecator || ActiveSupport::Deprecation._instance
|
||||
@deprecator = deprecator
|
||||
@message = message
|
||||
end
|
||||
|
||||
|
@ -29,10 +29,11 @@ module Deprecation
|
||||
# end
|
||||
def assert_deprecated(match = nil, deprecator = nil, &block)
|
||||
match, deprecator = nil, match if match.is_a?(ActiveSupport::Deprecation)
|
||||
|
||||
unless deprecator
|
||||
ActiveSupport.deprecator.warn("assert_deprecated without a deprecator is deprecated")
|
||||
deprecator = ActiveSupport::Deprecation._instance
|
||||
raise ArgumentError, "No deprecator given"
|
||||
end
|
||||
|
||||
result, warnings = collect_deprecations(deprecator, &block)
|
||||
assert !warnings.empty?, "Expected a deprecation warning within the block but received none"
|
||||
if match
|
||||
@ -51,11 +52,7 @@ def assert_deprecated(match = nil, deprecator = nil, &block)
|
||||
# assert_not_deprecated(ActiveSupport::Deprecation.new) do
|
||||
# CustomDeprecator.warn "message" # passes assertion, different deprecator
|
||||
# end
|
||||
def assert_not_deprecated(deprecator = nil, &block)
|
||||
unless deprecator
|
||||
ActiveSupport.deprecator.warn("assert_not_deprecated without a deprecator is deprecated")
|
||||
deprecator = ActiveSupport::Deprecation._instance
|
||||
end
|
||||
def assert_not_deprecated(deprecator, &block)
|
||||
result, deprecations = collect_deprecations(deprecator, &block)
|
||||
assert deprecations.empty?, "Expected no deprecation warning within the block but received #{deprecations.size}: \n #{deprecations * "\n "}"
|
||||
result
|
||||
@ -69,11 +66,7 @@ def assert_not_deprecated(deprecator = nil, &block)
|
||||
# ActiveSupport::Deprecation.new.warn "other message"
|
||||
# :result
|
||||
# end # => [:result, ["message"]]
|
||||
def collect_deprecations(deprecator = nil)
|
||||
unless deprecator
|
||||
ActiveSupport.deprecator.warn("collect_deprecations without a deprecator is deprecated")
|
||||
deprecator = ActiveSupport::Deprecation._instance
|
||||
end
|
||||
def collect_deprecations(deprecator)
|
||||
old_behavior = deprecator.behavior
|
||||
deprecations = []
|
||||
deprecator.behavior = Proc.new do |message, callstack|
|
||||
|
@ -47,8 +47,8 @@ def setup
|
||||
end
|
||||
end
|
||||
|
||||
test "assert_deprecated is deprecated without a deprecator" do
|
||||
assert_deprecated(ActiveSupport.deprecator) do
|
||||
test "assert_deprecated requires a deprecator" do
|
||||
assert_raises(ArgumentError) do
|
||||
assert_deprecated do
|
||||
ActiveSupport::Deprecation._instance.warn
|
||||
end
|
||||
@ -61,8 +61,8 @@ def setup
|
||||
end
|
||||
end
|
||||
|
||||
test "assert_not_deprecated is deprecated without a deprecator" do
|
||||
assert_deprecated(ActiveSupport.deprecator) do
|
||||
test "assert_not_deprecated requires a deprecator" do
|
||||
assert_raises(ArgumentError) do
|
||||
assert_not_deprecated { }
|
||||
end
|
||||
end
|
||||
@ -77,8 +77,8 @@ def setup
|
||||
assert_match "DEPRECATION WARNING:", result.last.sole
|
||||
end
|
||||
|
||||
test "collect_deprecations is deprecated without a deprecator" do
|
||||
assert_deprecated(ActiveSupport.deprecator) do
|
||||
test "collect_deprecations requires a deprecator" do
|
||||
assert_raises(ArgumentError) do
|
||||
collect_deprecations { }
|
||||
end
|
||||
end
|
||||
@ -116,15 +116,11 @@ def setup
|
||||
end
|
||||
end
|
||||
|
||||
test "Module::deprecate without a deprecator is deprecated" do
|
||||
test "Module::deprecate requires a deprecator" do
|
||||
klass = Class.new(Deprecatee)
|
||||
_, deprecations = collect_deprecations(ActiveSupport.deprecator) do
|
||||
assert_raises(ArgumentError) do
|
||||
klass.deprecate :zero
|
||||
end
|
||||
assert_match "Module.deprecate without a deprecator is deprecated", deprecations.sole
|
||||
assert_deprecated(/zero is deprecated/, ActiveSupport::Deprecation._instance) do
|
||||
klass.new.zero
|
||||
end
|
||||
end
|
||||
|
||||
test "DeprecatedObjectProxy" do
|
||||
@ -132,8 +128,8 @@ def setup
|
||||
assert_deprecated(/:bomb:/, @deprecator) { deprecated_object.to_s }
|
||||
end
|
||||
|
||||
test "DeprecatedObjectProxy without a deprecator is deprecated" do
|
||||
assert_deprecated(ActiveSupport.deprecator) do
|
||||
test "DeprecatedObjectProxy requires a deprecator" do
|
||||
assert_raises(ArgumentError) do
|
||||
ActiveSupport::Deprecation::DeprecatedObjectProxy.new(Object.new, ":bomb:")
|
||||
end
|
||||
end
|
||||
@ -302,7 +298,7 @@ def setup
|
||||
|
||||
test "DeprecatedInstanceVariableProxy" do
|
||||
instance = Deprecatee.new
|
||||
instance.fubar = ActiveSupport::Deprecation::DeprecatedInstanceVariableProxy.new(instance, :foo_bar, "@fubar", @deprecator)
|
||||
instance.fubar = ActiveSupport::Deprecation::DeprecatedInstanceVariableProxy.new(instance, :foo_bar, "@fubar", deprecator: @deprecator)
|
||||
instance.foo_bar = "foo bar!"
|
||||
|
||||
fubar_size = assert_deprecated("@fubar.size", @deprecator) { instance.fubar.size }
|
||||
@ -314,15 +310,15 @@ def setup
|
||||
|
||||
test "DeprecatedInstanceVariableProxy does not warn on inspect" do
|
||||
instance = Deprecatee.new
|
||||
instance.fubar = ActiveSupport::Deprecation::DeprecatedInstanceVariableProxy.new(instance, :foo_bar, "@fubar", @deprecator)
|
||||
instance.fubar = ActiveSupport::Deprecation::DeprecatedInstanceVariableProxy.new(instance, :foo_bar, "@fubar", deprecator: @deprecator)
|
||||
instance.foo_bar = "foo bar!"
|
||||
|
||||
fubar_inspected = assert_not_deprecated(@deprecator) { instance.fubar.inspect }
|
||||
assert_equal instance.foo_bar.inspect, fubar_inspected
|
||||
end
|
||||
|
||||
test "DeprecatedInstanceVariableProxy without a deprecator is deprecated" do
|
||||
assert_deprecated(ActiveSupport.deprecator) do
|
||||
test "DeprecatedInstanceVariableProxy requires a deprecator" do
|
||||
assert_raises(ArgumentError) do
|
||||
ActiveSupport::Deprecation::DeprecatedInstanceVariableProxy.new(Deprecatee.new, :foobar, "@fubar")
|
||||
end
|
||||
end
|
||||
@ -354,8 +350,8 @@ def setup
|
||||
end
|
||||
end
|
||||
|
||||
test "DeprecatedConstantProxy without a deprecator is deprecated" do
|
||||
assert_deprecated(ActiveSupport.deprecator) do
|
||||
test "DeprecatedConstantProxy requires a deprecator" do
|
||||
assert_raise(ArgumentError) do
|
||||
ActiveSupport::Deprecation::DeprecatedConstantProxy.new("Fuu", "Undeprecated::Foo")
|
||||
end
|
||||
end
|
||||
@ -383,9 +379,9 @@ def setup
|
||||
end
|
||||
end
|
||||
|
||||
test "deprecate_constant is deprecated without a deprecator" do
|
||||
test "deprecate_constant requires a deprecator" do
|
||||
legacy = Module.new.include(ActiveSupport::Deprecation::DeprecatedConstantAccessor)
|
||||
assert_deprecated("DeprecatedConstantAccessor.deprecate_constant without a deprecator is deprecated", ActiveSupport.deprecator) do
|
||||
assert_raises(ArgumentError) do
|
||||
legacy.deprecate_constant "OLD", "NEW"
|
||||
end
|
||||
end
|
||||
|
@ -207,6 +207,17 @@ Please refer to the [Changelog][active-support] for detailed changes.
|
||||
|
||||
### Removals
|
||||
|
||||
* 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`
|
||||
|
||||
* Remove deprecated `ActiveSupport::Deprecation` delegation to instance.
|
||||
|
||||
* Remove deprecated `SafeBuffer#clone_empty`.
|
||||
|
Loading…
Reference in New Issue
Block a user