Class: IDRegistry::RegistryMiddleware
- Inherits:
-
Object
- Object
- IDRegistry::RegistryMiddleware
- Defined in:
- lib/idregistry/middleware.rb
Overview
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.
Defined Under Namespace
Classes: ClearRegistry, SpawnRegistry
Instance Method Summary collapse
-
#call(env_) ⇒ Object
Wrap the Rack app with registry tasks.
-
#initialize(app_, tasks_ = [], opts_ = {}) ⇒ RegistryMiddleware
constructor
Create a middleware.
Constructor Details
#initialize(app_, tasks_ = [], opts_ = {}) ⇒ RegistryMiddleware
Create a middleware.
After the required Rack app argument, provide an array of tasks.
129 130 131 132 |
# File 'lib/idregistry/middleware.rb', line 129 def initialize(app_, tasks_=[], opts_={}) @app = app_ @tasks = tasks_ end |
Instance Method Details
#call(env_) ⇒ Object
Wrap the Rack app with registry tasks.
137 138 139 140 141 142 143 144 |
# 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 |