Class: IDRegistry::RegistryMiddleware::ClearRegistry

Inherits:
Object
  • Object
show all
Defined in:
lib/idregistry/middleware.rb

Overview

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.

Instance Method Summary collapse

Constructor Details

#initialize(registry_, &condition_) ⇒ ClearRegistry

Create a new ClearRegistry task. You must provide the registry and an optional condition block.



64
65
66
67
# File 'lib/idregistry/middleware.rb', line 64

def initialize(registry_, &condition_)
  @condition = condition_
  @registry = registry_
end

Instance Method Details

#post(env_) ⇒ Object

The post method for this task clears the registry if the condition block passes



75
76
77
78
79
# File 'lib/idregistry/middleware.rb', line 75

def post(env_)
  if !@condition || @condition.call(env_)
    @registry.clear
  end
end

#pre(env_) ⇒ Object

The pre method for this task does nothing.



70
71
# File 'lib/idregistry/middleware.rb', line 70

def pre(env_)
end