From bffe05f246ee8b8ae990fb3d9bfae757bcdcc565 Mon Sep 17 00:00:00 2001 From: Jean Boussier Date: Thu, 25 Jan 2024 10:02:58 +0100 Subject: [PATCH] Module#delegate stop accepting the private `as:` parameter The feature remains usable internally, but via `ActiveSupport::Delegation`, this way we don't allow third party use. --- actioncable/lib/action_cable/channel/broadcasting.rb | 2 +- actioncable/lib/action_cable/channel/naming.rb | 2 +- .../lib/active_support/core_ext/module/delegation.rb | 3 +-- activesupport/lib/active_support/current_attributes.rb | 4 ++-- activesupport/lib/active_support/duration.rb | 2 +- 5 files changed, 6 insertions(+), 7 deletions(-) diff --git a/actioncable/lib/action_cable/channel/broadcasting.rb b/actioncable/lib/action_cable/channel/broadcasting.rb index de9719ee24..a71716edb7 100644 --- a/actioncable/lib/action_cable/channel/broadcasting.rb +++ b/actioncable/lib/action_cable/channel/broadcasting.rb @@ -35,7 +35,7 @@ def serialize_broadcasting(object) # :nodoc: end end - delegate :broadcasting_for, :broadcast_to, to: :class, as: ClassMethods + ActiveSupport::Delegation.generate(self, [:broadcasting_for, :broadcast_to], to: :class, as: ClassMethods) end end end diff --git a/actioncable/lib/action_cable/channel/naming.rb b/actioncable/lib/action_cable/channel/naming.rb index 5f61070a77..b94f53c16a 100644 --- a/actioncable/lib/action_cable/channel/naming.rb +++ b/actioncable/lib/action_cable/channel/naming.rb @@ -18,7 +18,7 @@ def channel_name end end - delegate :channel_name, to: :class, as: ClassMethods + ActiveSupport::Delegation.generate(self, [:channel_name], to: :class, as: ClassMethods) end end end diff --git a/activesupport/lib/active_support/core_ext/module/delegation.rb b/activesupport/lib/active_support/core_ext/module/delegation.rb index 043fb19124..f306d55f39 100644 --- a/activesupport/lib/active_support/core_ext/module/delegation.rb +++ b/activesupport/lib/active_support/core_ext/module/delegation.rb @@ -157,7 +157,7 @@ class Module # Foo.new("Bar").name # raises NoMethodError: undefined method `name' # # The target method must be public, otherwise it will raise +NoMethodError+. - def delegate(*methods, to: nil, prefix: nil, allow_nil: nil, private: nil, as: nil) + def delegate(*methods, to: nil, prefix: nil, allow_nil: nil, private: nil) ::ActiveSupport::Delegation.generate( self, methods, @@ -166,7 +166,6 @@ def delegate(*methods, to: nil, prefix: nil, allow_nil: nil, private: nil, as: n prefix: prefix, allow_nil: allow_nil, private: private, - as: as, ) end diff --git a/activesupport/lib/active_support/current_attributes.rb b/activesupport/lib/active_support/current_attributes.rb index 8bd8be5e74..687e536bea 100644 --- a/activesupport/lib/active_support/current_attributes.rb +++ b/activesupport/lib/active_support/current_attributes.rb @@ -132,7 +132,7 @@ def attribute(*names, default: nil) end end - singleton_class.delegate(*names.flat_map { |name| [name, "#{name}="] }, to: :instance, as: self) + Delegation.generate(singleton_class, names.flat_map { |name| [name, "#{name}="] }, to: :instance, as: self) self.defaults = defaults.merge(names.index_with { default }) end @@ -184,7 +184,7 @@ def method_added(name) return if name == :initialize return unless public_method_defined?(name) return if respond_to?(name, true) - singleton_class.delegate(name, to: :instance, as: self) + Delegation.generate(singleton_class, [name], to: :instance, as: self) end end diff --git a/activesupport/lib/active_support/duration.rb b/activesupport/lib/active_support/duration.rb index 08038ffa12..87a1e90f55 100644 --- a/activesupport/lib/active_support/duration.rb +++ b/activesupport/lib/active_support/duration.rb @@ -221,7 +221,7 @@ def calculate_total_seconds(parts) end end - delegate :to_f, :positive?, :negative?, :zero?, :abs, to: :@value, as: Integer + Delegation.generate(self, [:to_f, :positive?, :negative?, :zero?, :abs], to: :@value, as: Integer) def initialize(value, parts, variable = nil) # :nodoc: @value, @parts = value, parts