Class: Eventboss::Middleware::Chain
- Inherits:
-
Object
- Object
- Eventboss::Middleware::Chain
- Defined in:
- lib/eventboss/middleware.rb
Instance Attribute Summary collapse
-
#entries ⇒ Object
readonly
Returns the value of attribute entries.
Instance Method Summary collapse
- #add(klass, options = {}) ⇒ Object
- #clear ⇒ Object
-
#initialize ⇒ Chain
constructor
A new instance of Chain.
- #invoke(*args) ⇒ Object
Constructor Details
#initialize ⇒ Chain
Returns a new instance of Chain.
6 7 8 |
# File 'lib/eventboss/middleware.rb', line 6 def initialize @entries = [] end |
Instance Attribute Details
#entries ⇒ Object (readonly)
Returns the value of attribute entries.
4 5 6 |
# File 'lib/eventboss/middleware.rb', line 4 def entries @entries end |
Instance Method Details
#add(klass, options = {}) ⇒ Object
10 11 12 |
# File 'lib/eventboss/middleware.rb', line 10 def add(klass, = {}) @entries << Entry.new(klass, ) end |
#clear ⇒ Object
27 28 29 |
# File 'lib/eventboss/middleware.rb', line 27 def clear @entries.clear end |
#invoke(*args) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/eventboss/middleware.rb', line 14 def invoke(*args) chain = @entries.map(&:build).reverse! invoke_lambda = lambda do if (mid = chain.pop) mid.call(*args, &invoke_lambda) else yield end end invoke_lambda.call end |