class IDRegistry::RegistryMiddleware

A Rack middleware that manages registries around a request.

Configure this middleware with a set of registry-related tasks, such as creating temporary registries scoped to the request, or clearing registries at the end of the request.

A task object must include two methods: pre and post. These methods are called before and after the request, and are passed the Rack environment hash.

Public Class Methods

new(app_, tasks_=[], opts_={}) click to toggle source

Create a middleware.

After the required Rack app argument, provide an array of tasks.

# File lib/idregistry/middleware.rb, line 129
def initialize(app_, tasks_=[], opts_={})
  @app = app_
  @tasks = tasks_
end

Public Instance Methods

call(env_) click to toggle source

Wrap the Rack app with registry tasks.

# File lib/idregistry/middleware.rb, line 137
def call(env_)
  begin
    @tasks.each{ |task_| task_.pre(env_) }
    return @app.call(env_)
  ensure
    @tasks.each{ |task_| task_.post(env_) }
  end
end