Class: ActionDispatch::MiddlewareStack
  
  
  
Overview
  
Defined Under Namespace
  
    
  
    
      Classes: InstrumentationProxy, Middleware
    
  
  Instance Attribute Summary collapse
  
  
    
      Instance Method Summary
      collapse
    
    
      
        - 
  
    
      #[](i)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
  
- 
  
    
      #build(app = nil, &block)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
  
- 
  
    
      #delete(target)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
Deletes a middleware from the middleware stack. 
 
- 
  
    
      #delete!(target)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
Deletes a middleware from the middleware stack. 
 
- 
  
    
      #each(&block)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
  
- 
  
    
      #initialize(*args) {|_self| ... } ⇒ MiddlewareStack 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    
A new instance of MiddlewareStack. 
 
- 
  
    
      #initialize_copy(other)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
  
- 
  
    
      #insert(index, klass, *args, &block)  ⇒ Object 
    
    
      (also: #insert_before)
    
  
  
  
  
  
  
  
  
  
    
  
- 
  
    
      #insert_after(index, *args, &block)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
  
- 
  
    
      #last  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
  
- 
  
    
      #move(target, source)  ⇒ Object 
    
    
      (also: #move_before)
    
  
  
  
  
  
  
  
  
  
    
  
- 
  
    
      #move_after(target, source)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
  
- 
  
    
      #size  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
  
- 
  
    
      #swap(target, *args, &block)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
  
- 
  
    
      #unshift(klass, *args, &block)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
  
- 
  
    
      #use(klass, *args, &block)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
  
Methods included from Enumerable
  #as_json, #compact_blank, #exclude?, #excluding, #in_order_of, #including, #index_by, #index_with, #many?, #maximum, #minimum, #pick, #pluck, #sole
  
  
  
  
  
  
  Constructor Details
  
    
  
  
    #initialize(*args) {|_self| ... } ⇒ MiddlewareStack 
  
  
  
  
    
Returns a new instance of MiddlewareStack.
   
 
  
    | 
76
77
78
79 | # File 'actionpack/lib/action_dispatch/middleware/stack.rb', line 76
def initialize(*args)
  @middlewares = []
  yield(self) if block_given?
end
 | 
 
  
 
  
    Instance Attribute Details
    
      
      
      
  
  
    #middlewares  ⇒ Object 
  
  
  
  
    
Returns the value of attribute middlewares.
   
 
  
  
    | 
74
75
76 | # File 'actionpack/lib/action_dispatch/middleware/stack.rb', line 74
def middlewares
  @middlewares
end
 | 
 
    
   
  
    Instance Method Details
    
      
  
  
    | 
93
94
95 | # File 'actionpack/lib/action_dispatch/middleware/stack.rb', line 93
def [](i)
  middlewares[i]
end
 | 
 
    
      
  
  
    #build(app = nil, &block)  ⇒ Object 
  
  
  
  
    | 
166
167
168
169
170
171
172
173
174
175 | # File 'actionpack/lib/action_dispatch/middleware/stack.rb', line 166
def build(app = nil, &block)
  instrumenting = ActiveSupport::Notifications.notifier.listening?(InstrumentationProxy::EVENT_NAME)
  middlewares.freeze.reverse.inject(app || block) do |a, e|
    if instrumenting
      e.build_instrumented(a)
    else
      e.build(a)
    end
  end
end
 | 
 
    
      
  
  
    #delete(target)  ⇒ Object 
  
  
  
  
    
Deletes a middleware from the middleware stack.
Returns the array of middlewares not including the deleted item, or returns nil if the target is not found.
   
 
  
  
    | 
131
132
133 | # File 'actionpack/lib/action_dispatch/middleware/stack.rb', line 131
def delete(target)
  middlewares.reject! { |m| m.name == target.name }
end
 | 
 
    
      
  
  
    #delete!(target)  ⇒ Object 
  
  
  
  
    
Deletes a middleware from the middleware stack.
Returns the array of middlewares not including the deleted item, or raises ‘RuntimeError` if the target is not found.
   
 
  
  
    | 
139
140
141 | # File 'actionpack/lib/action_dispatch/middleware/stack.rb', line 139
def delete!(target)
  delete(target) || (raise "No such middleware to remove: #{target.inspect}")
end
 | 
 
    
      
  
  
    #each(&block)  ⇒ Object 
  
  
  
  
    | 
81
82
83 | # File 'actionpack/lib/action_dispatch/middleware/stack.rb', line 81
def each(&block)
  @middlewares.each(&block)
end
 | 
 
    
      
  
  
    #initialize_copy(other)  ⇒ Object 
  
  
  
  
    | 
102
103
104 | # File 'actionpack/lib/action_dispatch/middleware/stack.rb', line 102
def initialize_copy(other)
  self.middlewares = other.middlewares.dup
end
 | 
 
    
      
  
  
    #insert(index, klass, *args, &block)  ⇒ Object 
  
  
    Also known as:
    insert_before
    
  
  
  
    | 
106
107
108
109 | # File 'actionpack/lib/action_dispatch/middleware/stack.rb', line 106
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 
  
  
  
  
    | 
114
115
116
117 | # File 'actionpack/lib/action_dispatch/middleware/stack.rb', line 114
def insert_after(index, *args, &block)
  index = assert_index(index, :after)
  insert(index + 1, *args, &block)
end
 | 
 
    
      
  
  
    | 
89
90
91 | # File 'actionpack/lib/action_dispatch/middleware/stack.rb', line 89
def last
  middlewares.last
end
 | 
 
    
      
  
  
    #move(target, source)  ⇒ Object 
  
  
    Also known as:
    move_before
    
  
  
  
    | 
143
144
145
146
147
148
149 | # File 'actionpack/lib/action_dispatch/middleware/stack.rb', line 143
def move(target, source)
  source_index = assert_index(source, :before)
  source_middleware = middlewares.delete_at(source_index)
  target_index = assert_index(target, :before)
  middlewares.insert(target_index, source_middleware)
end
 | 
 
    
      
  
  
    #move_after(target, source)  ⇒ Object 
  
  
  
  
    | 
153
154
155
156
157
158
159 | # File 'actionpack/lib/action_dispatch/middleware/stack.rb', line 153
def move_after(target, source)
  source_index = assert_index(source, :after)
  source_middleware = middlewares.delete_at(source_index)
  target_index = assert_index(target, :after)
  middlewares.insert(target_index + 1, source_middleware)
end
 | 
 
    
      
  
  
    | 
85
86
87 | # File 'actionpack/lib/action_dispatch/middleware/stack.rb', line 85
def size
  middlewares.size
end
 | 
 
    
      
  
  
    #swap(target, *args, &block)  ⇒ Object 
  
  
  
  
    | 
120
121
122
123
124 | # File 'actionpack/lib/action_dispatch/middleware/stack.rb', line 120
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 
  
  
  
  
    | 
97
98
99 | # File 'actionpack/lib/action_dispatch/middleware/stack.rb', line 97
def unshift(klass, *args, &block)
  middlewares.unshift(build_middleware(klass, args, block))
end
 | 
 
    
      
  
  
    #use(klass, *args, &block)  ⇒ Object 
  
  
  
  
    | 
161
162
163 | # File 'actionpack/lib/action_dispatch/middleware/stack.rb', line 161
def use(klass, *args, &block)
  middlewares.push(build_middleware(klass, args, block))
end
 |