Class: Sequent::Core::Middleware::Chain
- Inherits:
-
Object
- Object
- Sequent::Core::Middleware::Chain
- Defined in:
- lib/sequent/core/middleware/chain.rb
Instance Attribute Summary collapse
-
#entries ⇒ Object
readonly
Returns the value of attribute entries.
Instance Method Summary collapse
- #add(middleware) ⇒ Object
- #clear ⇒ Object
-
#initialize ⇒ Chain
constructor
A new instance of Chain.
- #invoke(*args, &invoker) ⇒ Object
Constructor Details
#initialize ⇒ Chain
Returns a new instance of Chain.
9 10 11 |
# File 'lib/sequent/core/middleware/chain.rb', line 9 def initialize clear end |
Instance Attribute Details
#entries ⇒ Object (readonly)
Returns the value of attribute entries.
7 8 9 |
# File 'lib/sequent/core/middleware/chain.rb', line 7 def entries @entries end |
Instance Method Details
#add(middleware) ⇒ Object
13 14 15 |
# File 'lib/sequent/core/middleware/chain.rb', line 13 def add(middleware) @entries.push(middleware) end |
#clear ⇒ Object
17 18 19 |
# File 'lib/sequent/core/middleware/chain.rb', line 17 def clear @entries = [] end |
#invoke(*args, &invoker) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/sequent/core/middleware/chain.rb', line 21 def invoke(*args, &invoker) chain = @entries.dup traverse_chain = -> do if chain.empty? invoker.call else chain.shift.call(*args, &traverse_chain) end end traverse_chain.call end |