Class: Toys::Middleware::Stack
- Inherits:
-
Object
- Object
- Toys::Middleware::Stack
- Defined in:
- lib/toys/middleware.rb
Overview
A stack of middleware specs.
Instance Attribute Summary collapse
-
#default_specs ⇒ Array<Toys::Middleware:Spec>
readonly
The default set of middleware specs.
-
#post_specs ⇒ Array<Toys::Middleware:Spec>
readonly
The middleware specs that follow the default set.
-
#pre_specs ⇒ Array<Toys::Middleware:Spec>
readonly
The middleware specs that precede the default set.
Instance Method Summary collapse
-
#add(middleware, *args, **kwargs, &block) ⇒ Object
Add a middleware spec to the stack, in the default location, which is at the end of pre_specs).
-
#build(middleware_lookup) ⇒ Array<Toys::Middleware>
Build the middleware in this stack.
-
#dup ⇒ Toys::Middleware::Stack
Duplicate this stack.
Instance Attribute Details
#default_specs ⇒ Array<Toys::Middleware:Spec> (readonly)
The default set of middleware specs.
281 282 283 |
# File 'lib/toys/middleware.rb', line 281 def default_specs @default_specs end |
#post_specs ⇒ Array<Toys::Middleware:Spec> (readonly)
The middleware specs that follow the default set.
287 288 289 |
# File 'lib/toys/middleware.rb', line 287 def post_specs @post_specs end |
#pre_specs ⇒ Array<Toys::Middleware:Spec> (readonly)
The middleware specs that precede the default set.
275 276 277 |
# File 'lib/toys/middleware.rb', line 275 def pre_specs @pre_specs end |
Instance Method Details
#add(name, *args, **kwargs, &block) ⇒ Object #add(array) ⇒ Object #add(middleware_object) ⇒ Object
Add a middleware spec to the stack, in the default location, which is at the end of pre_specs). See Toys::Middleware.spec for a description of the arguments you can pass.
298 299 300 |
# File 'lib/toys/middleware.rb', line 298 def add(middleware, *args, **kwargs, &block) pre_specs.push(Middleware.spec(middleware, *args, **kwargs, &block)) end |
#build(middleware_lookup) ⇒ Array<Toys::Middleware>
Build the middleware in this stack.
318 319 320 |
# File 'lib/toys/middleware.rb', line 318 def build(middleware_lookup) (@pre_specs + @default_specs + @post_specs).map { |spec| spec.build(middleware_lookup) } end |
#dup ⇒ Toys::Middleware::Stack
Duplicate this stack.
307 308 309 310 311 |
# File 'lib/toys/middleware.rb', line 307 def dup Stack.new(pre_specs: pre_specs.dup, post_specs: post_specs.dup, default_specs: default_specs.dup) end |