Class: Wytch::SiteCodeLoaderMiddleware

Inherits:
Object
  • Object
show all
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.

See Also:

Instance Method Summary collapse

Constructor Details

#initialize(app, coordinator) ⇒ SiteCodeLoaderMiddleware

Creates a new middleware instance.

Parameters:

  • app (#call)

    the Rack application to wrap

  • coordinator (ReloadCoordinator)

    the reload coordinator



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.

Parameters:

  • env (Hash)

    the Rack environment

Returns:

  • (Array)

    the Rack response tuple



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