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

View file

@ -90,8 +90,13 @@ module ActionDispatch
end end
def unshift(klass, *args, &block) 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
)
end
ruby2_keywords(:unshift) if respond_to?(:ruby2_keywords, true)
def initialize_copy(other) def initialize_copy(other)
self.middlewares = other.middlewares.dup self.middlewares = other.middlewares.dup
@ -99,8 +104,14 @@ module ActionDispatch
def insert(index, klass, *args, &block) def insert(index, klass, *args, &block)
index = assert_index(index, :before) 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
)
end
ruby2_keywords(:insert) if respond_to?(:ruby2_keywords, true)
alias_method :insert_before, :insert alias_method :insert_before, :insert
@ -108,12 +119,14 @@ module ActionDispatch
index = assert_index(index, :after) index = assert_index(index, :after)
insert(index + 1, *args, &block) insert(index + 1, *args, &block)
end end
ruby2_keywords(:insert_after) if respond_to?(:ruby2_keywords, true)
def swap(target, *args, &block) def swap(target, *args, &block)
index = assert_index(target, :before) index = assert_index(target, :before)
insert(index, *args, &block) insert(index, *args, &block)
middlewares.delete_at(index + 1) middlewares.delete_at(index + 1)
end end
ruby2_keywords(:swap) if respond_to?(:ruby2_keywords, true)
def delete(target) def delete(target)
middlewares.delete_if { |m| m.klass == target } middlewares.delete_if { |m| m.klass == target }

View file

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