Class: Lennarb::MiddlewareStack
- Inherits:
-
Object
- Object
- Lennarb::MiddlewareStack
- Defined in:
- lib/lennarb/middleware_stack.rb
Overview
Basic middleware stack implementation.
Instance Attribute Summary collapse
-
#app ⇒ Object
readonly
Returns the value of attribute app.
Instance Method Summary collapse
-
#clear ⇒ Object
Clear the middleware stack.
-
#initialize(app = nil) ⇒ MiddlewareStack
constructor
The app’s middleware stack.
-
#to_a ⇒ Object
Convert the middleware stack to an array.
-
#unshift(middleware, *args, &block) ⇒ Object
Add a middleware to the beginning of the stack.
-
#use(middleware, *args, &block) ⇒ Object
Insert a middleware in the stack.
Constructor Details
#initialize(app = nil) ⇒ MiddlewareStack
The app’s middleware stack.
11 12 13 14 |
# File 'lib/lennarb/middleware_stack.rb', line 11 def initialize(app = nil) @app = app @store = [] end |
Instance Attribute Details
#app ⇒ Object (readonly)
Returns the value of attribute app.
5 6 7 |
# File 'lib/lennarb/middleware_stack.rb', line 5 def app @app end |
Instance Method Details
#clear ⇒ Object
Clear the middleware stack.
44 45 46 |
# File 'lib/lennarb/middleware_stack.rb', line 44 def clear @store.clear end |
#to_a ⇒ Object
Convert the middleware stack to an array.
52 53 54 |
# File 'lib/lennarb/middleware_stack.rb', line 52 def to_a @store end |
#unshift(middleware, *args, &block) ⇒ Object
Add a middleware to the beginning of the stack.
36 37 38 |
# File 'lib/lennarb/middleware_stack.rb', line 36 def unshift(middleware, *args, &block) @store.unshift([middleware, args, block]) end |
#use(middleware, *args, &block) ⇒ Object
Insert a middleware in the stack.
24 25 26 |
# File 'lib/lennarb/middleware_stack.rb', line 24 def use(middleware, *args, &block) @store << [middleware, args, block] end |