Class: Kube::Cluster::Middleware::Stack
- Inherits:
-
Object
- Object
- Kube::Cluster::Middleware::Stack
- Defined in:
- lib/kube/cluster/middleware/stack.rb
Overview
An ordered pipeline of middleware that processes a manifest. Each middleware receives the manifest and mutates it in place.
stack = Kube::Cluster::Middleware::Stack.new do
use Middleware::ServiceForDeployment
use Middleware::Labels, app: "web"
use Middleware::Namespace, "production"
end
stack.call(manifest)
Instance Method Summary collapse
-
#call(manifest) ⇒ Object
Run the manifest through every middleware in order.
-
#empty? ⇒ Boolean
True when no middleware has been registered.
-
#initialize(&block) ⇒ Stack
constructor
A new instance of Stack.
-
#use(klass, *args, **kwargs) ⇒ Object
Register a middleware class with optional positional and keyword arguments.
Constructor Details
#initialize(&block) ⇒ Stack
Returns a new instance of Stack.
18 19 20 21 |
# File 'lib/kube/cluster/middleware/stack.rb', line 18 def initialize(&block) @middleware = [] instance_eval(&block) if block end |
Instance Method Details
#call(manifest) ⇒ Object
Run the manifest through every middleware in order. Each middleware mutates the manifest in place.
30 31 32 33 34 |
# File 'lib/kube/cluster/middleware/stack.rb', line 30 def call(manifest) @middleware.each do |klass, args, kwargs| klass.new(*args, **kwargs).call(manifest) end end |
#empty? ⇒ Boolean
True when no middleware has been registered.
37 38 39 |
# File 'lib/kube/cluster/middleware/stack.rb', line 37 def empty? @middleware.empty? end |
#use(klass, *args, **kwargs) ⇒ Object
Register a middleware class with optional positional and keyword arguments.
24 25 26 |
# File 'lib/kube/cluster/middleware/stack.rb', line 24 def use(klass, *args, **kwargs) @middleware << [klass, args, kwargs] end |