Class: ActionDispatch::MiddlewareStack

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/action_dispatch/middleware/stack.rb

Direct Known Subclasses

ActionController::MiddlewareStack

Defined Under Namespace

Classes: Middleware

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) {|_self| ... } ⇒ MiddlewareStack

Returns a new instance of MiddlewareStack.

Yields:

  • (_self)

Yield Parameters:



43
44
45
46
# File 'lib/action_dispatch/middleware/stack.rb', line 43

def initialize(*args)
  @middlewares = []
  yield(self) if block_given?
end

Instance Attribute Details

#middlewaresObject

Returns the value of attribute middlewares.



41
42
43
# File 'lib/action_dispatch/middleware/stack.rb', line 41

def middlewares
  @middlewares
end

Instance Method Details

#[](i) ⇒ Object



60
61
62
# File 'lib/action_dispatch/middleware/stack.rb', line 60

def [](i)
  middlewares[i]
end

#build(app = Proc.new) ⇒ Object



99
100
101
# File 'lib/action_dispatch/middleware/stack.rb', line 99

def build(app = Proc.new)
  middlewares.freeze.reverse.inject(app) { |a, e| e.build(a) }
end

#delete(target) ⇒ Object



90
91
92
93
# File 'lib/action_dispatch/middleware/stack.rb', line 90

def delete(target)
  target = get_class target
  middlewares.delete_if { |m| m.klass == target }
end

#eachObject



48
49
50
# File 'lib/action_dispatch/middleware/stack.rb', line 48

def each
  @middlewares.each { |x| yield x }
end

#initialize_copy(other) ⇒ Object



68
69
70
# File 'lib/action_dispatch/middleware/stack.rb', line 68

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

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



72
73
74
75
# File 'lib/action_dispatch/middleware/stack.rb', line 72

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

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



79
80
81
82
# File 'lib/action_dispatch/middleware/stack.rb', line 79

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

#lastObject



56
57
58
# File 'lib/action_dispatch/middleware/stack.rb', line 56

def last
  middlewares.last
end

#sizeObject



52
53
54
# File 'lib/action_dispatch/middleware/stack.rb', line 52

def size
  middlewares.size
end

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



84
85
86
87
88
# File 'lib/action_dispatch/middleware/stack.rb', line 84

def swap(target, *args, &block)
  index = assert_index(target, :before)
  insert(index, *args, &block)
  middlewares.delete_at(index + 1)
end

#unshift(klass, *args, &block) ⇒ Object



64
65
66
# File 'lib/action_dispatch/middleware/stack.rb', line 64

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

#use(klass, *args, &block) ⇒ Object



95
96
97
# File 'lib/action_dispatch/middleware/stack.rb', line 95

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