Class: BBServer::ExecutionStack
- Inherits:
-
Object
- Object
- BBServer::ExecutionStack
- Defined in:
- lib/bbserver/execution_stack.rb
Instance Method Summary collapse
- #execute(context) ⇒ Object
-
#initialize(handler_class, middlewares) ⇒ ExecutionStack
constructor
A new instance of ExecutionStack.
Constructor Details
#initialize(handler_class, middlewares) ⇒ ExecutionStack
Returns a new instance of ExecutionStack.
5 6 7 8 |
# File 'lib/bbserver/execution_stack.rb', line 5 def initialize(handler_class, middlewares) @handler_class = handler_class @middlewares = middlewares end |
Instance Method Details
#execute(context) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/bbserver/execution_stack.rb', line 10 def execute(context) chain = @middlewares.dup process = proc do |ctx| if chain.empty? handler = @handler_class.new(ctx) handler.handle else middleware = chain.shift middleware.call(ctx, process) end end process.call(context) end |