Skip to content

Commit

Permalink
Merge pull request #41907 from Shopify/remove-ruby2-keywords-check
Browse files Browse the repository at this point in the history
Stop checking if ruby2_keywords is defined
  • Loading branch information
byroot committed Apr 11, 2021
2 parents 2b1b75e + 3f59640 commit 97b87dc
Show file tree
Hide file tree
Showing 22 changed files with 39 additions and 65 deletions.
3 changes: 1 addition & 2 deletions actionmailer/lib/action_mailer/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -582,14 +582,13 @@ def set_payload_for_mail(payload, mail)
payload[:perform_deliveries] = mail.perform_deliveries
end

def method_missing(method_name, *args)
ruby2_keywords def method_missing(method_name, *args)
if action_methods.include?(method_name.to_s)
MessageDelivery.new(self, method_name, *args)
else
super
end
end
ruby2_keywords(:method_missing) if respond_to?(:ruby2_keywords, true)

def respond_to_missing?(method, include_all = false)
action_methods.include?(method.to_s) || super
Expand Down
3 changes: 1 addition & 2 deletions actionmailer/lib/action_mailer/delivery_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,9 @@ class DeliveryJob < ActiveJob::Base # :nodoc:
MSG
end

def perform(mailer, mail_method, delivery_method, *args) #:nodoc:
ruby2_keywords def perform(mailer, mail_method, delivery_method, *args) #:nodoc:
mailer.constantize.public_send(mail_method, *args).send(delivery_method)
end
ruby2_keywords(:perform) if respond_to?(:ruby2_keywords, true)

private
# "Deserialize" the mailer class name by hand in case another argument
Expand Down
3 changes: 1 addition & 2 deletions actionmailer/lib/action_mailer/message_delivery.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,14 @@ module ActionMailer
# Notifier.welcome(User.first).deliver_later # enqueue email delivery as a job through Active Job
# Notifier.welcome(User.first).message # a Mail::Message object
class MessageDelivery < Delegator
def initialize(mailer_class, action, *args) #:nodoc:
ruby2_keywords def initialize(mailer_class, action, *args) #:nodoc:
@mailer_class, @action, @args = mailer_class, action, args

# The mail is only processed if we try to call any methods on it.
# Typical usage will leave it unloaded and call deliver_later.
@processed_mailer = nil
@mail_message = nil
end
ruby2_keywords(:initialize) if respond_to?(:ruby2_keywords, true)

# Method calls are delegated to the Mail::Message that's ready to deliver.
def __getobj__ #:nodoc:
Expand Down
9 changes: 3 additions & 6 deletions actionmailer/lib/action_mailer/parameterized.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,33 +108,30 @@ def initialize(mailer, params)
end

private
def method_missing(method_name, *args)
ruby2_keywords def method_missing(method_name, *args)
if @mailer.action_methods.include?(method_name.to_s)
ActionMailer::Parameterized::MessageDelivery.new(@mailer, method_name, @params, *args)
else
super
end
end
ruby2_keywords(:method_missing) if respond_to?(:ruby2_keywords, true)

def respond_to_missing?(method, include_all = false)
@mailer.respond_to?(method, include_all)
end
end

class DeliveryJob < ActionMailer::DeliveryJob # :nodoc:
def perform(mailer, mail_method, delivery_method, params, *args)
ruby2_keywords def perform(mailer, mail_method, delivery_method, params, *args)
mailer.constantize.with(params).public_send(mail_method, *args).send(delivery_method)
end
ruby2_keywords(:perform) if respond_to?(:ruby2_keywords, true)
end

class MessageDelivery < ActionMailer::MessageDelivery # :nodoc:
def initialize(mailer_class, action, params, *args)
ruby2_keywords def initialize(mailer_class, action, params, *args)
super(mailer_class, action, *args)
@params = params
end
ruby2_keywords(:initialize) if respond_to?(:ruby2_keywords, true)

private
def processed_mailer
Expand Down
5 changes: 2 additions & 3 deletions actionpack/lib/abstract_controller/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,10 @@ def helper_method(*methods)
file, line = location.path, location.lineno

methods.each do |method|
_helpers_for_modification.class_eval <<-ruby_eval, file, line
def #{method}(*args, &block) # def current_user(*args, &block)
_helpers_for_modification.class_eval <<~ruby_eval, file, line
ruby2_keywords def #{method}(*args, &block) # ruby2_keywords def current_user(*args, &block)
controller.send(:'#{method}', *args, &block) # controller.send(:'current_user', *args, &block)
end # end
ruby2_keywords(:'#{method}') if respond_to?(:ruby2_keywords, true)
ruby_eval
end
end
Expand Down
15 changes: 5 additions & 10 deletions actionpack/lib/action_dispatch/middleware/stack.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,35 +88,31 @@ def [](i)
middlewares[i]
end

def unshift(klass, *args, &block)
ruby2_keywords def unshift(klass, *args, &block)
middlewares.unshift(build_middleware(klass, args, block))
end
ruby2_keywords(:unshift) if respond_to?(:ruby2_keywords, true)

def initialize_copy(other)
self.middlewares = other.middlewares.dup
end

def insert(index, klass, *args, &block)
ruby2_keywords def insert(index, klass, *args, &block)
index = assert_index(index, :before)
middlewares.insert(index, build_middleware(klass, args, block))
end
ruby2_keywords(:insert) if respond_to?(:ruby2_keywords, true)

alias_method :insert_before, :insert

def insert_after(index, *args, &block)
ruby2_keywords def insert_after(index, *args, &block)
index = assert_index(index, :after)
insert(index + 1, *args, &block)
end
ruby2_keywords(:insert_after) if respond_to?(:ruby2_keywords, true)

def swap(target, *args, &block)
ruby2_keywords def swap(target, *args, &block)
index = assert_index(target, :before)
insert(index, *args, &block)
middlewares.delete_at(index + 1)
end
ruby2_keywords(:swap) if respond_to?(:ruby2_keywords, true)

def delete(target)
middlewares.delete_if { |m| m.klass == target }
Expand All @@ -140,10 +136,9 @@ def move_after(target, source)
middlewares.insert(target_index + 1, source_middleware)
end

def use(klass, *args, &block)
ruby2_keywords def use(klass, *args, &block)
middlewares.push(build_middleware(klass, args, block))
end
ruby2_keywords(:use) if respond_to?(:ruby2_keywords, true)

def build(app = nil, &block)
instrumenting = ActiveSupport::Notifications.notifier.listening?(InstrumentationProxy::EVENT_NAME)
Expand Down
3 changes: 1 addition & 2 deletions actionpack/lib/action_dispatch/testing/integration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ def respond_to_missing?(method, _)
end

# Delegate unhandled messages to the current session instance.
def method_missing(method, *args, &block)
ruby2_keywords def method_missing(method, *args, &block)
if integration_session.respond_to?(method)
integration_session.public_send(method, *args, &block).tap do
copy_session_variables!
Expand All @@ -431,7 +431,6 @@ def method_missing(method, *args, &block)
super
end
end
ruby2_keywords(:method_missing) if respond_to?(:ruby2_keywords, true)
end
end

Expand Down
5 changes: 2 additions & 3 deletions actionview/lib/action_view/test_case.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,10 @@ def determine_default_helper_class(name)
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)
_helpers_for_modification.module_eval <<~end_eval, __FILE__, __LINE__ + 1
ruby2_keywords def #{method}(*args, &block) # ruby2_keywords def current_user(*args, &block)
_test_case.send(:'#{method}', *args, &block) # _test_case.send(:'current_user', *args, &block)
end # end
ruby2_keywords(:'#{method}') if respond_to?(:ruby2_keywords, true)
end_eval
end
end
Expand Down
2 changes: 1 addition & 1 deletion actionview/test/template/form_helper/form_with_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2120,7 +2120,7 @@ def #{selector}(field, *args, &proc)
end
RUBY_EVAL
end
ruby2_keywords(:fields) if respond_to?(:ruby2_keywords, true)
ruby2_keywords(:fields)
end

def test_form_with_with_labelled_builder
Expand Down
8 changes: 4 additions & 4 deletions activejob/lib/active_job/arguments.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,10 @@ def ruby2_keywords_hash(hash)
_ruby2_keywords_hash(**hash)
end

private def _ruby2_keywords_hash(*args)
args.last
end
ruby2_keywords(:_ruby2_keywords_hash) if respond_to?(:ruby2_keywords, true)
private
ruby2_keywords def _ruby2_keywords_hash(*args)
args.last
end
end
end
}
Expand Down
3 changes: 1 addition & 2 deletions activejob/lib/active_job/core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def set(options = {})

# Creates a new job instance. Takes the arguments that will be
# passed to the perform method.
def initialize(*arguments)
ruby2_keywords def initialize(*arguments)
@arguments = arguments
@job_id = SecureRandom.uuid
@queue_name = self.class.queue_name
Expand All @@ -97,7 +97,6 @@ def initialize(*arguments)
@exception_executions = {}
@timezone = Time.zone&.name
end
ruby2_keywords(:initialize) if respond_to?(:ruby2_keywords, true)

# Returns a hash with the job data that can safely be passed to the
# queuing adapter.
Expand Down
3 changes: 1 addition & 2 deletions activejob/lib/active_job/enqueuing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,9 @@ def perform_later(...)
end

private
def job_or_instantiate(*args) # :doc:
ruby2_keywords def job_or_instantiate(*args) # :doc:
args.first.is_a?(self) ? args.first : new(*args)
end
ruby2_keywords(:job_or_instantiate) if respond_to?(:ruby2_keywords, true)
end

# Enqueues the job to be performed by the queue adapter.
Expand Down
5 changes: 2 additions & 3 deletions activemodel/lib/active_model/attribute_methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ def define_proxy_call(code_generator, name, target, *extra)
defn <<
body <<
"end" <<
"ruby2_keywords(:'#{name}') if respond_to?(:ruby2_keywords, true)"
"ruby2_keywords(:'#{name}')"
end

class AttributeMethodMatcher #:nodoc:
Expand Down Expand Up @@ -461,15 +461,14 @@ 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)
ruby2_keywords def method_missing(method, *args, &block)
if respond_to_without_attributes?(method, true)
super
else
match = matched_attribute_method(method.to_s)
match ? attribute_missing(match, *args, &block) : super
end
end
ruby2_keywords(:method_missing) if respond_to?(:ruby2_keywords, true)

# +attribute_missing+ is like +method_missing+, but for attributes. When
# +method_missing+ is called we check to see if there is a matching
Expand Down
6 changes: 2 additions & 4 deletions activerecord/lib/active_record/migration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -656,10 +656,9 @@ def maintain_test_schema! #:nodoc:
end
end

def method_missing(name, *args, &block) #:nodoc:
ruby2_keywords def method_missing(name, *args, &block) #:nodoc:
nearest_delegate.send(name, *args, &block)
end
ruby2_keywords(:method_missing) if respond_to?(:ruby2_keywords, true)

def migrate(direction)
new.migrate direction
Expand Down Expand Up @@ -914,7 +913,7 @@ def connection
@connection || ActiveRecord::Base.connection
end

def method_missing(method, *arguments, &block)
ruby2_keywords def method_missing(method, *arguments, &block)
arg_list = arguments.map(&:inspect) * ", "

say_with_time "#{method}(#{arg_list})" do
Expand All @@ -931,7 +930,6 @@ def method_missing(method, *arguments, &block)
connection.send(method, *arguments, &block)
end
end
ruby2_keywords(:method_missing) if respond_to?(:ruby2_keywords, true)

def copy(destination, sources, options = {})
copied = []
Expand Down
5 changes: 2 additions & 3 deletions activerecord/lib/active_record/migration/command_recorder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def #{method}(*args, &block) # def create_table(*args, &block)
record(:"#{method}", args, &block) # record(:create_table, args, &block)
end # end
EOV
ruby2_keywords(method) if respond_to?(:ruby2_keywords, true)
ruby2_keywords(method)
end
alias :add_belongs_to :add_reference
alias :remove_belongs_to :remove_reference
Expand Down Expand Up @@ -279,14 +279,13 @@ def respond_to_missing?(method, _)
end

# Forwards any missing method call to the \target.
def method_missing(method, *args, &block)
ruby2_keywords def method_missing(method, *args, &block)
if delegate.respond_to?(method)
delegate.public_send(method, *args, &block)
else
super
end
end
ruby2_keywords(:method_missing) if respond_to?(:ruby2_keywords, true)
end
end
end
5 changes: 2 additions & 3 deletions activerecord/lib/active_record/relation/delegation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def #{method}(...)
define_method(method) do |*args, &block|
scoping { klass.public_send(method, *args, &block) }
end
ruby2_keywords(method) if respond_to?(:ruby2_keywords, true)
ruby2_keywords(method)
end
end
end
Expand Down Expand Up @@ -101,15 +101,14 @@ def name
end

private
def method_missing(method, *args, &block)
ruby2_keywords def method_missing(method, *args, &block)
if @klass.respond_to?(method)
@klass.generate_relation_method(method)
scoping { @klass.public_send(method, *args, &block) }
else
super
end
end
ruby2_keywords(:method_missing) if respond_to?(:ruby2_keywords, true)
end

module ClassMethods # :nodoc:
Expand Down
2 changes: 1 addition & 1 deletion activerecord/lib/active_record/scoping/named.rb
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ def scope(name, body, &block)
scope
end
end
singleton_class.send(:ruby2_keywords, name) if respond_to?(:ruby2_keywords, true)
singleton_class.send(:ruby2_keywords, name)

generate_relation_method(name)
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ def respond_to_missing?(name, include_private = false)
#{target}.respond_to?(name) || super
end
def method_missing(method, *args, &block)
ruby2_keywords def method_missing(method, *args, &block)
if #{target}.respond_to?(method)
#{target}.public_send(method, *args, &block)
else
Expand All @@ -318,7 +318,6 @@ def method_missing(method, *args, &block)
end
end
end
ruby2_keywords(:method_missing) if respond_to?(:ruby2_keywords, true)
RUBY
end
end
6 changes: 2 additions & 4 deletions activesupport/lib/active_support/core_ext/object/try.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

module ActiveSupport
module Tryable #:nodoc:
def try(method_name = nil, *args, &b)
ruby2_keywords def try(method_name = nil, *args, &b)
if method_name.nil? && block_given?
if b.arity == 0
instance_eval(&b)
Expand All @@ -15,9 +15,8 @@ def try(method_name = nil, *args, &b)
public_send(method_name, *args, &b)
end
end
ruby2_keywords(:try) if respond_to?(:ruby2_keywords, true)

def try!(method_name = nil, *args, &b)
ruby2_keywords def try!(method_name = nil, *args, &b)
if method_name.nil? && block_given?
if b.arity == 0
instance_eval(&b)
Expand All @@ -28,7 +27,6 @@ def try!(method_name = nil, *args, &b)
public_send(method_name, *args, &b)
end
end
ruby2_keywords(:try!) if respond_to?(:ruby2_keywords, true)
end
end

Expand Down

0 comments on commit 97b87dc

Please sign in to comment.