Class: ActionDispatch::MiddlewareStack
Relationships & Source Files | |
Namespace Children | |
Classes:
| |
Extension / Inclusion / Inheritance Descendants | |
Subclasses:
ActionController::MiddlewareStack
|
|
Super Chains via Extension / Inclusion / Inheritance | |
Instance Chain:
|
|
Inherits: | Object |
Defined in: | actionpack/lib/action_dispatch/middleware/stack.rb |
Overview
Read more about [Rails middleware stack](guides.rubyonrails.org/rails_on_rack.html#action-dispatcher-middleware-stack) in the guides.
Class Method Summary
- .new(*args) {|_self| ... } ⇒ MiddlewareStack constructor
Instance Attribute Summary
- #middlewares rw
::Enumerable
- Included
#many? | Returns |
Instance Method Summary
- #[](i)
- #build(app = nil, &block)
-
#delete(target)
Deletes a middleware from the middleware stack.
-
#delete!(target)
Deletes a middleware from the middleware stack.
- #each(&block)
- #initialize_copy(other)
- #insert(index, klass, *args, &block) (also: #insert_before)
- #insert_after(index, *args, &block)
-
#insert_before(index, klass, *args, &block)
Alias for #insert.
- #last
- #move(target, source) (also: #move_before)
- #move_after(target, source)
-
#move_before(target, source)
Alias for #move.
- #size
- #swap(target, *args, &block)
- #unshift(klass, *args, &block)
- #use(klass, *args, &block)
::Enumerable
- Included
#compact_blank | Returns a new |
#exclude? | The negative of the |
#excluding | Returns a copy of the enumerable excluding the specified elements. |
#in_order_of | Returns a new |
#including | Returns a new array that includes the passed elements. |
#index_by | Convert an enumerable to a hash, using the block result as the key and the element as the value. |
#index_with | Convert an enumerable to a hash, using the element as the key and the block result as the value. |
#maximum | Calculates the maximum from the extracted elements. |
#minimum | Calculates the minimum from the extracted elements. |
#pick | Extract the given key from the first element in the enumerable. |
#pluck | Extract the given key from each element in the enumerable. |
#sole | Returns the sole item in the enumerable. |
#without | Alias for Enumerable#excluding. |
Constructor Details
.new(*args) {|_self| ... } ⇒ MiddlewareStack
# File 'actionpack/lib/action_dispatch/middleware/stack.rb', line 76
def initialize(*args) @middlewares = [] yield(self) if block_given? end
Instance Attribute Details
#middlewares (rw)
[ GitHub ]# File 'actionpack/lib/action_dispatch/middleware/stack.rb', line 74
attr_accessor :middlewares
Instance Method Details
#[](i)
[ GitHub ]# File 'actionpack/lib/action_dispatch/middleware/stack.rb', line 93
def [](i) middlewares[i] end
#build(app = nil, &block)
[ GitHub ]# 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)
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.
# File 'actionpack/lib/action_dispatch/middleware/stack.rb', line 131
def delete(target) middlewares.reject! { |m| m.name == target.name } end
#delete!(target)
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.
# 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)
[ GitHub ]# File 'actionpack/lib/action_dispatch/middleware/stack.rb', line 81
def each(&block) @middlewares.each(&block) end
#initialize_copy(other)
[ GitHub ]# 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) Also known as: #insert_before
[ GitHub ]# 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)
[ GitHub ]# 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
#insert_before(index, klass, *args, &block)
Alias for #insert.
# File 'actionpack/lib/action_dispatch/middleware/stack.rb', line 112
alias_method :insert_before, :insert
#last
[ GitHub ]# File 'actionpack/lib/action_dispatch/middleware/stack.rb', line 89
def last middlewares.last end
#move(target, source) Also known as: #move_before
[ GitHub ]# 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)
[ GitHub ]# 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
#move_before(target, source)
Alias for #move.
# File 'actionpack/lib/action_dispatch/middleware/stack.rb', line 151
alias_method :move_before, :move
#size
[ GitHub ]# File 'actionpack/lib/action_dispatch/middleware/stack.rb', line 85
def size middlewares.size end
#swap(target, *args, &block)
[ GitHub ]# 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)
[ GitHub ]# 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)
[ GitHub ]# File 'actionpack/lib/action_dispatch/middleware/stack.rb', line 161
def use(klass, *args, &block) middlewares.push(build_middleware(klass, args, block)) end