class IDRegistry::RegistryMiddleware::ClearRegistry

A registry task that clears a registry at the end of a request.

You may also provide an optional condition block, which is called and passed the Rack env to determine whether the registry should be cleared. If no condition block is provided, the registry is always cleared.

Public Class Methods

new(registry_, opts_={}, &condition_) click to toggle source

Create a new ClearRegistry task. You must provide the registry and an optional condition block. If you set the :before_request option to true, the registry clearing will take place at the beginning of the request rather than the end.

# File lib/idregistry/middleware.rb, line 67
def initialize(registry_, opts_={}, &condition_)
  @condition = condition_
  @registry = registry_
  @before = opts_[:before_request]
end

Public Instance Methods

post(env_) click to toggle source

The pre method applies if :before_request is not set.

# File lib/idregistry/middleware.rb, line 81
def post(env_)
  if !@before && (!@condition || @condition.call(env_))
    @registry.clear
  end
end
pre(env_) click to toggle source

The pre method applies if :before_request is set.

# File lib/idregistry/middleware.rb, line 74
def pre(env_)
  if @before && (!@condition || @condition.call(env_))
    @registry.clear
  end
end