Class: CaptainConfig::PumaMiddleware

Inherits:
Object
  • Object
show all
Defined in:
lib/captain_config/middlewares/puma_middleware.rb

Overview

Using the ‘rack.after_reply` hook provided by Puma for running code after the response has been sent to the client.

Constant Summary collapse

RACK_AFTER_REPLY =
::Puma::Const::RACK_AFTER_REPLY

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ PumaMiddleware

Returns a new instance of PumaMiddleware.



6
7
8
# File 'lib/captain_config/middlewares/puma_middleware.rb', line 6

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/captain_config/middlewares/puma_middleware.rb', line 10

def call(env)
  service = CaptainConfig::Service.last_created_service

  if service
    # Load if it hasn't already been loaded (eg. first request).
    service.load unless service.loaded?

    # Then reload after every request.
    env[RACK_AFTER_REPLY] << lambda { service.load }
  end

  @app.call env
end