Class: ActionDispatch::MiddlewareStack

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

Direct Known Subclasses

ActionController::MiddlewareStack

Defined Under Namespace

Classes: Middleware

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Methods included from Enumerable

#as_json, #exclude?, #index_by, #many?, #sum

Constructor Details

- (MiddlewareStack) initialize(*args) {|_self| ... }

Returns a new instance of MiddlewareStack

Yields:

  • (_self)

Yield Parameters:



57
58
59
60
# File 'actionpack/lib/action_dispatch/middleware/stack.rb', line 57

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

Instance Attribute Details

- (Object) middlewares

Returns the value of attribute middlewares



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

def middlewares
  @middlewares
end

Instance Method Details

- (Object) [](i)



74
75
76
# File 'actionpack/lib/action_dispatch/middleware/stack.rb', line 74

def [](i)
  middlewares[i]
end

- (Object) build(app = nil, &block)



115
116
117
118
119
# File 'actionpack/lib/action_dispatch/middleware/stack.rb', line 115

def build(app = nil, &block)
  app ||= block
  raise "MiddlewareStack#build requires an app" unless app
  middlewares.freeze.reverse.inject(app) { |a, e| e.build(a) }
end

- (Object) delete(target)



106
107
108
# File 'actionpack/lib/action_dispatch/middleware/stack.rb', line 106

def delete(target)
  middlewares.delete target
end

- (Object) each



62
63
64
# File 'actionpack/lib/action_dispatch/middleware/stack.rb', line 62

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

- (Object) initialize_copy(other)



83
84
85
# File 'actionpack/lib/action_dispatch/middleware/stack.rb', line 83

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

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



87
88
89
90
91
# File 'actionpack/lib/action_dispatch/middleware/stack.rb', line 87

def insert(index, *args, &block)
  index = assert_index(index, :before)
  middleware = self.class::Middleware.new(*args, &block)
  middlewares.insert(index, middleware)
end

- (Object) insert_after(index, *args, &block)



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

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

- (Object) last



70
71
72
# File 'actionpack/lib/action_dispatch/middleware/stack.rb', line 70

def last
  middlewares.last
end

- (Object) size



66
67
68
# File 'actionpack/lib/action_dispatch/middleware/stack.rb', line 66

def size
  middlewares.size
end

- (Object) swap(target, *args, &block)



100
101
102
103
104
# File 'actionpack/lib/action_dispatch/middleware/stack.rb', line 100

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

- (Object) unshift(*args, &block)



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

def unshift(*args, &block)
  middleware = self.class::Middleware.new(*args, &block)
  middlewares.unshift(middleware)
end

- (Object) use(*args, &block)



110
111
112
113
# File 'actionpack/lib/action_dispatch/middleware/stack.rb', line 110

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