Class: IDRegistry::RegistryMiddleware::SpawnRegistry
- Inherits:
-
Object
- Object
- IDRegistry::RegistryMiddleware::SpawnRegistry
- Defined in:
- lib/idregistry/middleware.rb
Overview
A registry task that spawns a registry scoped to this request.
You must provide a locked registry configuration to use as a template. The spawned registry will use the given configuration. You must also provide a key, which will be used to store the spawned registry in the Rack environment so that your application can access it.
Instance Method Summary collapse
-
#initialize(template_, envkey_) ⇒ SpawnRegistry
constructor
Create a new ClearRegistry task.
-
#post(env_) ⇒ Object
The post method for this task clears the spawned registry.
-
#pre(env_) ⇒ Object
The pre method for this task creates a new registry.
Constructor Details
#initialize(template_, envkey_) ⇒ SpawnRegistry
Create a new ClearRegistry task. You must provide a locked template configuration and a key into the Rack environment.
96 97 98 99 100 |
# File 'lib/idregistry/middleware.rb', line 96 def initialize(template_, envkey_) @template = template_ @envkey = envkey_ @registry = nil end |
Instance Method Details
#post(env_) ⇒ Object
The post method for this task clears the spawned registry.
108 109 110 111 112 113 114 |
# File 'lib/idregistry/middleware.rb', line 108 def post(env_) if @registry @registry.clear @registry = nil env_.delete(@envkey) end end |
#pre(env_) ⇒ Object
The pre method for this task creates a new registry.
103 104 105 |
# File 'lib/idregistry/middleware.rb', line 103 def pre(env_) @registry = env_[@envkey] = @template.spawn_registry end |