Skip to content

Commit 04f9439

Browse files
committed
Fix Ruby 2.7 warnings for ActionController::Metal.use
1 parent 2e9d4f5 commit 04f9439

File tree

3 files changed

+19
-12
lines changed

3 files changed

+19
-12
lines changed

actionpack/lib/action_controller/metal.rb

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ module ActionController
1515
#
1616
class MiddlewareStack < ActionDispatch::MiddlewareStack #:nodoc:
1717
class Middleware < ActionDispatch::MiddlewareStack::Middleware #:nodoc:
18-
def initialize(klass, args, actions, strategy, block)
18+
def initialize(klass, args, actions, strategy, block, &build_block)
1919
@actions = actions
2020
@strategy = strategy
21-
super(klass, args, block)
21+
super(klass, args, block, &build_block)
2222
end
2323

2424
def valid?(action)
@@ -56,7 +56,9 @@ def build_middleware(klass, *args, &block)
5656
list = except
5757
end
5858

59-
Middleware.new(klass, args, list, strategy, block)
59+
Middleware.new(klass, args, list, strategy, block) do |app|
60+
klass.new(app, *args, &block)
61+
end
6062
end
6163
end
6264

@@ -218,8 +220,14 @@ def self.inherited(base) # :nodoc:
218220

219221
# Pushes the given Rack middleware and its arguments to the bottom of the
220222
# middleware stack.
221-
def self.use(*args, &block)
222-
middleware_stack.use(*args, &block)
223+
if RUBY_VERSION >= "2.7"
224+
def self.use(...)
225+
middleware_stack.use(...)
226+
end
227+
else
228+
def self.use(*args, &block)
229+
middleware_stack.use(*args, &block)
230+
end
223231
end
224232

225233
# Alias for +middleware_stack+.

actionpack/lib/action_dispatch/middleware/stack.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,5 @@ def build_middleware(klass, *args, &block)
151151
klass.new(app, *args, &block)
152152
end
153153
end
154-
ruby2_keywords(:build_middleware) if respond_to?(:ruby2_keywords, true)
155154
end
156155
end

actionpack/test/controller/new_base/middleware_test.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
module MiddlewareTest
66
class MyMiddleware
7-
def initialize(app)
7+
def initialize(app, kw: nil)
88
@app = app
99
end
1010

@@ -17,7 +17,7 @@ def call(env)
1717
end
1818

1919
class ExclaimerMiddleware
20-
def initialize(app)
20+
def initialize(app, kw: nil)
2121
@app = app
2222
end
2323

@@ -46,8 +46,8 @@ class MyController < ActionController::Metal
4646
use BlockMiddleware do |config|
4747
config.configurable_message = "Configured by block."
4848
end
49-
use MyMiddleware
50-
middleware.insert_before MyMiddleware, ExclaimerMiddleware
49+
use MyMiddleware, kw: 1
50+
middleware.insert_before MyMiddleware, ExclaimerMiddleware, kw: 1
5151

5252
def index
5353
self.response_body = "Hello World"
@@ -58,8 +58,8 @@ class InheritedController < MyController
5858
end
5959

6060
class ActionsController < ActionController::Metal
61-
use MyMiddleware, only: :show
62-
middleware.insert_before MyMiddleware, ExclaimerMiddleware, except: :index
61+
use MyMiddleware, only: :show, kw: 1
62+
middleware.insert_before MyMiddleware, ExclaimerMiddleware, except: :index, kw: 1
6363

6464
def index
6565
self.response_body = "index"

0 commit comments

Comments
 (0)