Cleanup usage of ruby2_keywords

Now that we no longer support Ruby 2.7, many `ruby2_keyword` calls
can be eliminated.

The ones that are left could be eliminated but would end up substantially
slower or more compliacated so I left them for now.
This commit is contained in:
Jean Boussier 2024-01-05 14:07:24 +01:00
parent 1702b6cbfd
commit ef65e5fb32
18 changed files with 54 additions and 80 deletions

@ -625,17 +625,16 @@ def set_payload_for_mail(payload, mail)
payload[:perform_deliveries] = mail.perform_deliveries
end
def method_missing(method_name, *args)
if action_methods.include?(method_name.to_s)
MessageDelivery.new(self, method_name, *args)
def method_missing(method_name, ...)
if action_methods.include?(method_name.name)
MessageDelivery.new(self, method_name, ...)
else
super
end
end
ruby2_keywords(:method_missing)
def respond_to_missing?(method, include_all = false)
action_methods.include?(method.to_s) || super
action_methods.include?(method.name) || super
end
end

@ -114,14 +114,13 @@ def initialize(mailer, params)
end
private
def method_missing(method_name, *args)
if @mailer.action_methods.include?(method_name.to_s)
ActionMailer::Parameterized::MessageDelivery.new(@mailer, method_name, @params, *args)
def method_missing(method_name, ...)
if @mailer.action_methods.include?(method_name.name)
ActionMailer::Parameterized::MessageDelivery.new(@mailer, method_name, @params, ...)
else
super
end
end
ruby2_keywords(:method_missing)
def respond_to_missing?(method, include_all = false)
@mailer.respond_to?(method, include_all)
@ -129,11 +128,10 @@ def respond_to_missing?(method, include_all = false)
end
class MessageDelivery < ActionMailer::MessageDelivery # :nodoc:
def initialize(mailer_class, action, params, *args)
super(mailer_class, action, *args)
def initialize(mailer_class, action, params, ...)
super(mailer_class, action, ...)
@params = params
end
ruby2_keywords(:initialize)
private
def processed_mailer

@ -148,7 +148,7 @@ def eager_load! # :nodoc:
#
# ==== Returns
# * <tt>self</tt>
def process(action, *args)
def process(action, ...)
@_action_name = action.to_s
unless action_name = _find_action_name(@_action_name)
@ -157,9 +157,8 @@ def process(action, *args)
@_response_body = nil
process_action(action_name, *args)
process_action(action_name, ...)
end
ruby2_keywords(:process)
# Delegates to the class's ::controller_path.
def controller_path

@ -7,10 +7,9 @@ module Collector
def self.generate_method_for_mime(mime)
sym = mime.is_a?(Symbol) ? mime : mime.to_sym
class_eval <<-RUBY, __FILE__, __LINE__ + 1
def #{sym}(*args, &block)
custom(Mime[:#{sym}], *args, &block)
def #{sym}(...)
custom(Mime[:#{sym}], ...)
end
ruby2_keywords(:#{sym})
RUBY
end
@ -23,7 +22,7 @@ def #{sym}(*args, &block)
end
private
def method_missing(symbol, *args, &block)
def method_missing(symbol, ...)
unless mime_constant = Mime[symbol]
raise NoMethodError, "To respond to a custom format, register it as a MIME type first: " \
"https://guides.rubyonrails.org/action_controller_overview.html#restful-downloads. " \
@ -34,11 +33,10 @@ def method_missing(symbol, *args, &block)
if Mime::SET.include?(mime_constant)
AbstractController::Collector.generate_method_for_mime(mime_constant)
public_send(symbol, *args, &block)
public_send(symbol, ...)
else
super
end
end
ruby2_keywords(:method_missing)
end
end

@ -131,10 +131,9 @@ def helper_method(*methods)
# controller.send(:'current_user', *args, &block)
# end
_helpers_for_modification.class_eval <<~ruby_eval.lines.map(&:strip).join(";"), file, line
def #{method}(*args, &block)
controller.send(:'#{method}', *args, &block)
def #{method}(...)
controller.send(:'#{method}', ...)
end
ruby2_keywords(:'#{method}')
ruby_eval
end
end

@ -247,14 +247,13 @@ def assert_routing(path, options, defaults = {}, extras = {}, message = nil)
end
# ROUTES TODO: These assertions should really work in an integration context
def method_missing(selector, *args, &block)
def method_missing(selector, ...)
if defined?(@controller) && @controller && defined?(@routes) && @routes && @routes.named_routes.route_defined?(selector)
@controller.public_send(selector, *args, &block)
@controller.public_send(selector, ...)
else
super
end
end
ruby2_keywords(:method_missing)
private
def create_routes

@ -431,16 +431,15 @@ def respond_to_missing?(method, _)
end
# Delegate unhandled messages to the current session instance.
def method_missing(method, *args, &block)
def method_missing(method, ...)
if integration_session.respond_to?(method)
integration_session.public_send(method, *args, &block).tap do
integration_session.public_send(method, ...).tap do
copy_session_variables!
end
else
super
end
end
ruby2_keywords(:method_missing)
end
end

@ -171,10 +171,9 @@ def helper_method(*methods)
# Almost a duplicate from ActionController::Helpers
methods.flatten.each do |method|
_helpers_for_modification.module_eval <<~end_eval, __FILE__, __LINE__ + 1
def #{method}(*args, &block) # def current_user(*args, &block)
_test_case.send(:'#{method}', *args, &block) # _test_case.send(:'current_user', *args, &block)
end # end
ruby2_keywords(:'#{method}')
def #{method}(...) # def current_user(*args, &block)
_test_case.send(:'#{method}', ...) # _test_case.send(:'current_user', *args, &block)
end # end
end_eval
end
end
@ -416,7 +415,7 @@ def view_assigns
end]
end
def method_missing(selector, *args)
def method_missing(selector, ...)
begin
routes = @controller.respond_to?(:_routes) && @controller._routes
rescue
@ -426,12 +425,11 @@ def method_missing(selector, *args)
if routes &&
(routes.named_routes.route_defined?(selector) ||
routes.mounted_helpers.method_defined?(selector))
@controller.__send__(selector, *args)
@controller.__send__(selector, ...)
else
super
end
end
ruby2_keywords(:method_missing)
def respond_to_missing?(name, include_private = false)
begin

@ -66,7 +66,6 @@ module AttributeMethods
NAME_COMPILABLE_REGEXP = /\A[a-zA-Z_]\w*[!?=]?\z/
CALL_COMPILABLE_REGEXP = /\A[a-zA-Z_]\w*[!?]?\z/
FORWARD_PARAMETERS = "*args"
included do
class_attribute :attribute_aliases, instance_writer: false, default: {}
@ -432,10 +431,8 @@ def define_call(code_generator, name, target_name, mangled_name, parameters, cal
"send(#{call_args.join(", ")})"
end
modifier = parameters == FORWARD_PARAMETERS ? "ruby2_keywords " : ""
batch <<
"#{modifier}def #{mangled_name}(#{parameters || ''})" <<
"def #{mangled_name}(#{parameters || ''})" <<
body <<
"end"
end
@ -449,7 +446,7 @@ class AttributeMethodPattern # :nodoc:
def initialize(prefix: "", suffix: "", parameters: nil)
@prefix = prefix
@suffix = suffix
@parameters = parameters.nil? ? FORWARD_PARAMETERS : parameters
@parameters = parameters.nil? ? "..." : parameters
@regex = /\A(?:#{Regexp.escape(@prefix)})(.*)(?:#{Regexp.escape(@suffix)})\z/
@proxy_target = "#{@prefix}attribute#{@suffix}"
@method_name = "#{prefix}%s#{suffix}"
@ -477,24 +474,22 @@ def method_name(attr_name)
# It's also possible to instantiate related objects, so a <tt>Client</tt>
# class belonging to the +clients+ table with a +master_id+ foreign key
# can instantiate master through <tt>Client#master</tt>.
def method_missing(method, *args, &block)
def method_missing(method, ...)
if respond_to_without_attributes?(method, true)
super
else
match = matched_attribute_method(method.to_s)
match ? attribute_missing(match, *args, &block) : super
match = matched_attribute_method(method.name)
match ? attribute_missing(match, ...) : super
end
end
ruby2_keywords(:method_missing)
# +attribute_missing+ is like +method_missing+, but for attributes. When
# +method_missing+ is called we check to see if there is a matching
# attribute method. If so, we tell +attribute_missing+ to dispatch the
# attribute. This method can be overloaded to customize the behavior.
def attribute_missing(match, *args, &block)
__send__(match.proxy_target, match.attr_name, *args, &block)
def attribute_missing(match, ...)
__send__(match.proxy_target, match.attr_name, ...)
end
ruby2_keywords(:attribute_missing)
# A +Person+ instance with a +name+ attribute can ask
# <tt>person.respond_to?(:name)</tt>, <tt>person.respond_to?(:name=)</tt>,

@ -20,16 +20,15 @@ def register(type_name, klass = nil, &block)
registrations[type_name] = block
end
def lookup(symbol, *args)
def lookup(symbol, ...)
registration = registrations[symbol]
if registration
registration.call(symbol, *args)
registration.call(symbol, ...)
else
raise ArgumentError, "Unknown type #{symbol.inspect}"
end
end
ruby2_keywords(:lookup)
private
attr_reader :registrations

@ -730,10 +730,9 @@ def maintain_test_schema! # :nodoc:
end
end
def method_missing(name, *args, &block) # :nodoc:
nearest_delegate.send(name, *args, &block)
def method_missing(name, ...) # :nodoc:
nearest_delegate.send(name, ...)
end
ruby2_keywords(:method_missing)
def migrate(direction)
new.migrate direction

@ -377,14 +377,13 @@ def respond_to_missing?(method, _)
end
# Forwards any missing method call to the \target.
def method_missing(method, *args, &block)
def method_missing(method, ...)
if delegate.respond_to?(method)
delegate.public_send(method, *args, &block)
delegate.public_send(method, ...)
else
super
end
end
ruby2_keywords(:method_missing)
end
end
end

@ -6,13 +6,12 @@ class Migration
# to the connection adapter.
class DefaultStrategy < ExecutionStrategy # :nodoc:
private
def method_missing(method, *arguments, &block)
connection.send(method, *arguments, &block)
def method_missing(method, ...)
connection.send(method, ...)
end
ruby2_keywords(:method_missing)
def respond_to_missing?(method, *)
connection.respond_to?(method) || super
def respond_to_missing?(method, include_private = false)
connection.respond_to?(method, include_private) || super
end
def connection

@ -79,10 +79,9 @@ def #{method}(...)
end
RUBY
else
define_method(method) do |*args, &block|
scoping { klass.public_send(method, *args, &block) }
define_method(method) do |*args, **kwargs, &block|
scoping { klass.public_send(method, *args, **kwargs, &block) }
end
ruby2_keywords(method)
end
end
end
@ -113,17 +112,16 @@ def name
end
private
def method_missing(method, *args, &block)
def method_missing(method, ...)
if @klass.respond_to?(method)
unless Delegation.uncacheable_methods.include?(method)
@klass.generate_relation_method(method)
end
scoping { @klass.public_send(method, *args, &block) }
scoping { @klass.public_send(method, ...) }
else
super
end
end
ruby2_keywords(:method_missing)
end
module ClassMethods # :nodoc:

@ -336,9 +336,9 @@ def respond_to_missing?(name, include_private = false)
#{target}.respond_to?(name) || super
end
def method_missing(method, *args, &block)
def method_missing(method, ...)
if #{target}.respond_to?(method)
#{target}.public_send(method, *args, &block)
#{target}.public_send(method, ...)
else
begin
super
@ -355,7 +355,6 @@ def method_missing(method, *args, &block)
end
end
end
ruby2_keywords(:method_missing)
RUBY
end
end

@ -177,15 +177,14 @@ def current_instances_key
@current_instances_key ||= name.to_sym
end
def method_missing(name, *args, &block)
def method_missing(name, ...)
# Caches the method definition as a singleton method of the receiver.
#
# By letting #delegate handle it, we avoid an enclosure that'll capture args.
singleton_class.delegate name, to: :instance
send(name, *args, &block)
send(name, ...)
end
ruby2_keywords(:method_missing)
def respond_to_missing?(name, _)
super || instance.respond_to?(name)

@ -21,7 +21,7 @@ module RaiseWarnings # :nodoc:
%r{/lib/mail/parsers/.*assigned but unused variable - testEof}
)
def warn(message, *)
def warn(message, ...)
return if SUPPRESSED_WARNINGS.match?(message)
super
@ -32,7 +32,6 @@ def warn(message, *)
raise message
end
ruby2_keywords :warn if respond_to?(:ruby2_keywords, true)
end
end

@ -221,14 +221,13 @@ def respond_to_missing?(name, _)
# If the class method does not have a method, then send the method call
# to the Railtie instance.
def method_missing(name, *args, &block)
def method_missing(name, ...)
if !abstract_railtie? && instance.respond_to?(name)
instance.public_send(name, *args, &block)
instance.public_send(name, ...)
else
super
end
end
ruby2_keywords(:method_missing)
# receives an instance variable identifier, set the variable value if is
# blank and append given block to value, which will be used later in