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

View file

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

View file

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