Skip to content

Commit 2323823

Browse files
authored
Merge pull request rails#51638 from Earlopain/deprecate-as-proxy-object
Deprecate `ActiveSupport::ProxyObject`
2 parents 0121f23 + ea7d3c5 commit 2323823

File tree

3 files changed

+28
-5
lines changed

3 files changed

+28
-5
lines changed

activesupport/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
* Deprecate `ActiveSupport::ProxyObject` in favor of Ruby's buildin `BasicObject`
2+
3+
*Earlopain*
4+
15
* `stub_const` now accepts a `exists: false` parameter to allow stubbing missing constants.
26

37
*Jean Boussier*
Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
11
# frozen_string_literal: true
22

33
module ActiveSupport
4-
# = Active Support Proxy \Object
5-
#
6-
# A class with no predefined methods that behaves similarly to Ruby's
7-
# BasicObject. Used for proxy classes.
8-
class ProxyObject < ::BasicObject
4+
class ProxyObject < ::BasicObject # :nodoc:
95
undef_method :==
106
undef_method :equal?
117

128
# Let ActiveSupport::ProxyObject at least raise exceptions.
139
def raise(*args)
1410
::Object.send(:raise, *args)
1511
end
12+
13+
def self.inherited(_subclass)
14+
::ActiveSupport.deprecator.warn(<<~MSG)
15+
ActiveSupport::ProxyObject is deprecated and will be removed in Rails 7.3.
16+
Use Ruby's buildin BasicObject instead.
17+
MSG
18+
end
1619
end
1720
end
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# frozen_string_literal: true
2+
3+
require_relative "abstract_unit"
4+
5+
class ProxyObjectTest < ActiveSupport::TestCase
6+
def test_accessing_proxy_object_is_deprecated
7+
proxy = assert_deprecated(ActiveSupport.deprecator) do
8+
Class.new(ActiveSupport::ProxyObject) do
9+
def some_method
10+
"foo"
11+
end
12+
end
13+
end
14+
assert_equal("foo", proxy.new.some_method)
15+
end
16+
end

0 commit comments

Comments
 (0)