Class: ActionController::MiddlewareStack

Inherits:
Array
  • Object
show all
Defined in:
lib/action_controller/middleware_stack.rb

Defined Under Namespace

Classes: Middleware

Instance Method Summary collapse

Constructor Details

#initialize(*args, &block) ⇒ MiddlewareStack

Returns a new instance of MiddlewareStack.



83
84
85
86
# File 'lib/action_controller/middleware_stack.rb', line 83

def initialize(*args, &block)
  super(*args)
  block.call(self) if block_given?
end

Instance Method Details

#activeObject



111
112
113
# File 'lib/action_controller/middleware_stack.rb', line 111

def active
  find_all { |middleware| middleware.active? }
end

#build(app) ⇒ Object



115
116
117
# File 'lib/action_controller/middleware_stack.rb', line 115

def build(app)
  active.reverse.inject(app) { |a, e| e.build(a) }
end

#insert(index, *args, &block) ⇒ Object Also known as: insert_before



88
89
90
91
92
# File 'lib/action_controller/middleware_stack.rb', line 88

def insert(index, *args, &block)
  index = self.index(index) unless index.is_a?(Integer)
  middleware = Middleware.new(*args, &block)
  super(index, middleware)
end

#insert_after(index, *args, &block) ⇒ Object



96
97
98
99
# File 'lib/action_controller/middleware_stack.rb', line 96

def insert_after(index, *args, &block)
  index = self.index(index) unless index.is_a?(Integer)
  insert(index + 1, *args, &block)
end

#swap(target, *args, &block) ⇒ Object



101
102
103
104
# File 'lib/action_controller/middleware_stack.rb', line 101

def swap(target, *args, &block)
  insert_before(target, *args, &block)
  delete(target)
end

#use(*args, &block) ⇒ Object



106
107
108
109
# File 'lib/action_controller/middleware_stack.rb', line 106

def use(*args, &block)
  middleware = Middleware.new(*args, &block)
  push(middleware)
end