Class: IDRegistry::RegistryMiddleware::SpawnRegistry

Inherits:
Object
  • Object
show all
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

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.



102
103
104
105
106
# File 'lib/idregistry/middleware.rb', line 102

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.



114
115
116
117
118
119
120
# File 'lib/idregistry/middleware.rb', line 114

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.



109
110
111
# File 'lib/idregistry/middleware.rb', line 109

def pre(env_)
  @registry = env_[@envkey] = @template.spawn_registry
end