1
module ActionController
2
class MiddlewareStack < Array
4
def self.new(klass, *args, &block)
12
attr_reader :args, :block
14
def initialize(klass, *args, &block)
17
options = args.extract_options!
18
if options.has_key?(:if)
19
@conditional = options.delete(:if)
23
args << options unless options.empty?
30
if @klass.respond_to?(:call)
32
elsif @klass.is_a?(Class)
35
@klass.to_s.constantize
42
return false unless klass
44
if @conditional.respond_to?(:call)
54
klass == middleware.klass
58
klass == middleware.to_s.constantize
64
args.each { |arg| str += ", #{arg.inspect}" }
70
klass.new(app, *build_args, &block)
72
klass.new(app, *build_args)
79
Array(args).map { |arg| arg.respond_to?(:call) ? arg.call : arg }
83
def initialize(*args, &block)
85
block.call(self) if block_given?
88
def insert(index, *args, &block)
89
index = self.index(index) unless index.is_a?(Integer)
90
middleware = Middleware.new(*args, &block)
91
super(index, middleware)
94
alias_method :insert_before, :insert
96
def insert_after(index, *args, &block)
97
index = self.index(index) unless index.is_a?(Integer)
98
insert(index + 1, *args, &block)
101
def swap(target, *args, &block)
102
insert_before(target, *args, &block)
106
def use(*args, &block)
107
middleware = Middleware.new(*args, &block)
112
find_all { |middleware| middleware.active? }
116
active.reverse.inject(app) { |a, e| e.build(a) }