Class: Jackhammer::MiddlewareCollection
- Inherits:
-
Object
- Object
- Jackhammer::MiddlewareCollection
- Defined in:
- lib/jackhammer/middleware_collection.rb
Defined Under Namespace
Classes: Entry
Instance Method Summary collapse
- #call(*args, **kwargs, &block) ⇒ Object
-
#initialize ⇒ MiddlewareCollection
constructor
A new instance of MiddlewareCollection.
- #use(klass, *args, **kwargs, &block) ⇒ Object
Constructor Details
#initialize ⇒ MiddlewareCollection
Returns a new instance of MiddlewareCollection.
3 4 5 |
# File 'lib/jackhammer/middleware_collection.rb', line 3 def initialize @entries = [] end |
Instance Method Details
#call(*args, **kwargs, &block) ⇒ Object
11 12 13 14 15 16 17 18 19 |
# File 'lib/jackhammer/middleware_collection.rb', line 11 def call(*args, **kwargs, &block) call_chain = @entries.map(&:instantiate) + [block] traverse = proc do |*procargs, **prockwargs| call_chain.shift.call(*procargs, **prockwargs, &traverse) unless call_chain.empty? end traverse.call(*args, **kwargs) end |