1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Fix Ruby 2.7 warnings on MiddlewareStackProxy

Especially this is caused on `config.app_middleware.insert_after` in our
code base:

2b9edb777b/activerecord/lib/active_record/railtie.rb (L88-L90)
2b9edb777b/activerecord/lib/active_record/migration.rb (L556-L557)
This commit is contained in:
Ryuta Kamizono 2019-12-25 17:08:31 +09:00
parent 5324f2cb09
commit fedde239dc
2 changed files with 28 additions and 10 deletions
actionpack/lib/action_dispatch/middleware
railties/lib/rails

View file

@ -90,8 +90,13 @@ module ActionDispatch
end
def unshift(klass, *args, &block)
middlewares.unshift(build_middleware(klass, args, block))
middlewares.unshift(
build_middleware(klass, args, block) do |app|
klass.new(app, *args, &block)
end
)
end
ruby2_keywords(:unshift) if respond_to?(:ruby2_keywords, true)
def initialize_copy(other)
self.middlewares = other.middlewares.dup
@ -99,8 +104,14 @@ module ActionDispatch
def insert(index, klass, *args, &block)
index = assert_index(index, :before)
middlewares.insert(index, build_middleware(klass, args, block))
middlewares.insert(
index,
build_middleware(klass, args, block) do |app|
klass.new(app, *args, &block)
end
)
end
ruby2_keywords(:insert) if respond_to?(:ruby2_keywords, true)
alias_method :insert_before, :insert
@ -108,12 +119,14 @@ module ActionDispatch
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)
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 }

View file

@ -41,34 +41,39 @@ module Rails
end
def insert_before(*args, &block)
@operations << [__method__, args, block]
@operations << -> middleware { middleware.send(__method__, *args, &block) }
end
ruby2_keywords(:insert_before) if respond_to?(:ruby2_keywords, true)
alias :insert :insert_before
def insert_after(*args, &block)
@operations << [__method__, args, block]
@operations << -> middleware { middleware.send(__method__, *args, &block) }
end
ruby2_keywords(:insert_after) if respond_to?(:ruby2_keywords, true)
def swap(*args, &block)
@operations << [__method__, args, block]
@operations << -> middleware { middleware.send(__method__, *args, &block) }
end
ruby2_keywords(:swap) if respond_to?(:ruby2_keywords, true)
def use(*args, &block)
@operations << [__method__, args, block]
@operations << -> middleware { middleware.send(__method__, *args, &block) }
end
ruby2_keywords(:use) if respond_to?(:ruby2_keywords, true)
def delete(*args, &block)
@delete_operations << [__method__, args, block]
@delete_operations << -> middleware { middleware.send(__method__, *args, &block) }
end
def unshift(*args, &block)
@operations << [__method__, args, block]
@operations << -> middleware { middleware.send(__method__, *args, &block) }
end
ruby2_keywords(:unshift) if respond_to?(:ruby2_keywords, true)
def merge_into(other) #:nodoc:
(@operations + @delete_operations).each do |operation, args, block|
other.send(operation, *args, &block)
(@operations + @delete_operations).each do |operation|
operation.call(other)
end
other