Skip to content
Permalink
Browse files

Use ruby2_keywords + send_keyword_hash for ActionDispatch::Middleware…

…Stack

* Makes it explicit where the conversion can happen.
  • Loading branch information
eregon committed Oct 24, 2019
1 parent f414dd5 commit b5fd497a585649b73647e6e1632a7558b441d95f
Showing with 17 additions and 6 deletions.
  1. +17 −6 actionpack/lib/action_dispatch/middleware/stack.rb
@@ -3,6 +3,17 @@
require "active_support/inflector/methods"
require "active_support/dependencies"

class BasicObject
alias_method :send_keyword_hash, :__send__ unless respond_to?(:send_keyword_hash)
end

class Module
unless respond_to?(:ruby2_keywords, true)
def self.ruby2_keywords(*)
end
end
end

module ActionDispatch
class MiddlewareStack
class Middleware
@@ -34,7 +45,7 @@ def inspect
end

def build(app)
klass.new(app, *args, &block)
klass.send_keyword_hash(:new, app, *args, &block)
end

def build_instrumented(app)
@@ -88,27 +99,27 @@ def [](i)
middlewares[i]
end

def unshift(klass, *args, &block)
ruby2_keywords def unshift(klass, *args, &block)
middlewares.unshift(build_middleware(klass, args, block))
end

def initialize_copy(other)
self.middlewares = other.middlewares.dup
end

def insert(index, klass, *args, &block)
ruby2_keywords def insert(index, klass, *args, &block)
index = assert_index(index, :before)
middlewares.insert(index, build_middleware(klass, args, block))
end

alias_method :insert_before, :insert

def insert_after(index, *args, &block)
ruby2_keywords def insert_after(index, *args, &block)
index = assert_index(index, :after)
insert(index + 1, *args, &block)
end

def swap(target, *args, &block)
ruby2_keywords def swap(target, *args, &block)
index = assert_index(target, :before)
insert(index, *args, &block)
middlewares.delete_at(index + 1)
@@ -118,7 +129,7 @@ def delete(target)
middlewares.delete_if { |m| m.klass == target }
end

def use(klass, *args, &block)
ruby2_keywords def use(klass, *args, &block)
middlewares.push(build_middleware(klass, args, block))
end

0 comments on commit b5fd497

Please sign in to comment.
You can’t perform that action at this time.