Fix Ruby 2.7 warnings for `ActionController::Metal.use`

This commit is contained in:
Ryuta Kamizono 2019-12-26 17:59:13 +09:00
parent 2e9d4f531c
commit 04f94394b3
3 changed files with 19 additions and 12 deletions

View File

@ -15,10 +15,10 @@ module ActionController
#
class MiddlewareStack < ActionDispatch::MiddlewareStack #:nodoc:
class Middleware < ActionDispatch::MiddlewareStack::Middleware #:nodoc:
def initialize(klass, args, actions, strategy, block)
def initialize(klass, args, actions, strategy, block, &build_block)
@actions = actions
@strategy = strategy
super(klass, args, block)
super(klass, args, block, &build_block)
end
def valid?(action)
@ -56,7 +56,9 @@ module ActionController
list = except
end
Middleware.new(klass, args, list, strategy, block)
Middleware.new(klass, args, list, strategy, block) do |app|
klass.new(app, *args, &block)
end
end
end
@ -218,8 +220,14 @@ module ActionController
# Pushes the given Rack middleware and its arguments to the bottom of the
# middleware stack.
def self.use(*args, &block)
middleware_stack.use(*args, &block)
if RUBY_VERSION >= "2.7"
def self.use(...)
middleware_stack.use(...)
end
else
def self.use(*args, &block)
middleware_stack.use(*args, &block)
end
end
# Alias for +middleware_stack+.

View File

@ -151,6 +151,5 @@ module ActionDispatch
klass.new(app, *args, &block)
end
end
ruby2_keywords(:build_middleware) if respond_to?(:ruby2_keywords, true)
end
end

View File

@ -4,7 +4,7 @@ require "abstract_unit"
module MiddlewareTest
class MyMiddleware
def initialize(app)
def initialize(app, kw: nil)
@app = app
end
@ -17,7 +17,7 @@ module MiddlewareTest
end
class ExclaimerMiddleware
def initialize(app)
def initialize(app, kw: nil)
@app = app
end
@ -46,8 +46,8 @@ module MiddlewareTest
use BlockMiddleware do |config|
config.configurable_message = "Configured by block."
end
use MyMiddleware
middleware.insert_before MyMiddleware, ExclaimerMiddleware
use MyMiddleware, kw: 1
middleware.insert_before MyMiddleware, ExclaimerMiddleware, kw: 1
def index
self.response_body = "Hello World"
@ -58,8 +58,8 @@ module MiddlewareTest
end
class ActionsController < ActionController::Metal
use MyMiddleware, only: :show
middleware.insert_before MyMiddleware, ExclaimerMiddleware, except: :index
use MyMiddleware, only: :show, kw: 1
middleware.insert_before MyMiddleware, ExclaimerMiddleware, except: :index, kw: 1
def index
self.response_body = "index"