Class: Wytch::SiteCodeLoaderMiddleware
- Inherits:
-
Object
- Object
- Wytch::SiteCodeLoaderMiddleware
- Defined in:
- lib/wytch/site_code_loader_middleware.rb
Overview
Rack middleware that triggers hot reloading before each request.
This middleware wraps the base application and coordinates with the ReloadCoordinator to ensure site code and content are reloaded when files change. It acquires a read lock during request processing to prevent reloads from interfering with rendering.
Instance Method Summary collapse
-
#call(env) ⇒ Array
Handles a Rack request.
-
#initialize(app, coordinator) ⇒ SiteCodeLoaderMiddleware
constructor
Creates a new middleware instance.
Constructor Details
#initialize(app, coordinator) ⇒ SiteCodeLoaderMiddleware
Creates a new middleware instance.
17 18 19 20 |
# File 'lib/wytch/site_code_loader_middleware.rb', line 17 def initialize(app, coordinator) @app = app @coordinator = coordinator end |
Instance Method Details
#call(env) ⇒ Array
Handles a Rack request.
Triggers a reload check, then processes the request while holding a read lock to prevent concurrent reloads.
29 30 31 32 33 34 35 |
# File 'lib/wytch/site_code_loader_middleware.rb', line 29 def call(env) @coordinator.reload! @coordinator.reload_lock.with_read_lock { @app.call(env) } end |