Class: ActionDispatch::MiddlewareStack
Relationships & Source Files | |
Namespace Children | |
Classes:
| |
Extension / Inclusion / Inheritance Descendants | |
Subclasses:
ActionController::MiddlewareStack
|
|
Super Chains via Extension / Inclusion / Inheritance | |
Instance Chain:
self,
::Enumerable
|
|
Inherits: | Object |
Defined in: | actionpack/lib/action_dispatch/middleware/stack.rb |
Constant Summary
::Enumerable
- Included
INDEX_WITH_DEFAULT
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)
- #each
- #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. |
#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. |
#pick | Extract the given key from the first element in the enumerable. |
#pluck | Extract the given key from each element in the enumerable. |
#sum | Calculates a sum from the elements. |
#without | Alias for |
Constructor Details
.new(*args) {|_self| ... } ⇒ MiddlewareStack
# File 'actionpack/lib/action_dispatch/middleware/stack.rb', line 70
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 68
attr_accessor :middlewares
Instance Method Details
#[](i)
[ GitHub ]# File 'actionpack/lib/action_dispatch/middleware/stack.rb', line 87
def [](i) middlewares[i] end
#build(app = nil, &block)
[ GitHub ]# File 'actionpack/lib/action_dispatch/middleware/stack.rb', line 148
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)
[ GitHub ]# File 'actionpack/lib/action_dispatch/middleware/stack.rb', line 121
def delete(target) middlewares.delete_if { |m| m.klass == target } end
#each
[ GitHub ]# File 'actionpack/lib/action_dispatch/middleware/stack.rb', line 75
def each @middlewares.each { |x| yield x } end
#initialize_copy(other)
[ GitHub ]# File 'actionpack/lib/action_dispatch/middleware/stack.rb', line 96
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 100
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 108
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 106
alias_method :insert_before, :insert
#last
[ GitHub ]# File 'actionpack/lib/action_dispatch/middleware/stack.rb', line 83
def last middlewares.last end
#move(target, source) Also known as: #move_before
[ GitHub ]# File 'actionpack/lib/action_dispatch/middleware/stack.rb', line 125
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 135
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 133
alias_method :move_before, :move
#size
[ GitHub ]# File 'actionpack/lib/action_dispatch/middleware/stack.rb', line 79
def size middlewares.size end
#swap(target, *args, &block)
[ GitHub ]# File 'actionpack/lib/action_dispatch/middleware/stack.rb', line 114
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 91
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 143
def use(klass, *args, &block) middlewares.push(build_middleware(klass, args, block)) end