Class: Hanami::Providers::Rack Private

Inherits:
Dry::System::Provider::Source
  • Object
show all
Defined in:
lib/hanami/providers/rack.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Provider source to register Rack integration components in Hanami slices.

Instance Method Summary collapse

Instance Method Details

#prepareObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 2.0.0



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/hanami/providers/rack.rb', line 17

def prepare
  Dry::Monitor.load_extensions(:rack)

  # Explicitly register the Rack middleware events on our notifications bus. The Dry::Monitor
  # rack extension (activated above) does register these globally, but if the notifications
  # bus has been used before this provider loads, then it will have created its own separate
  # locally copy of all registered events as of that moment in time, which will not included
  # the Rack events globally reigstered above.
  notifications = target["notifications"]
  notifications.register_event(Dry::Monitor::Rack::Middleware::REQUEST_START)
  notifications.register_event(Dry::Monitor::Rack::Middleware::REQUEST_STOP)
  notifications.register_event(Dry::Monitor::Rack::Middleware::REQUEST_ERROR)
end

#startObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 2.0.0



32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/hanami/providers/rack.rb', line 32

def start
  target.start :logger

  monitor_middleware = Dry::Monitor::Rack::Middleware.new(
    target["notifications"],
    clock: Dry::Monitor::Clock.new(unit: :microsecond)
  )

  rack_logger = Hanami::Web::RackLogger.new(target[:logger], env: target.env)
  rack_logger.attach(monitor_middleware)

  register "monitor", monitor_middleware
end