Class: Debugbar::TrackCurrentRequest

Inherits:
Object
  • Object
show all
Defined in:
lib/debugbar/middlewares/track_current_request.rb

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ TrackCurrentRequest

Returns a new instance of TrackCurrentRequest.



3
4
5
# File 'lib/debugbar/middlewares/track_current_request.rb', line 3

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/debugbar/middlewares/track_current_request.rb', line 7

def call(env)
  # we don't check if debugbar is enabled because this middleware is only added when it is

  # Set `ignore` attribute to reuse it anywhere
  Debugbar::Current.ignore = Debugbar.config.ignore_request?(env)

  return @app.call(env) if Debugbar::Current.ignore?

  Debugbar::Current.new_request!(SecureRandom.uuid)

  res = @app.call(env)

  # TODO: Remove this if statement?
  # We check meta because the frontend doesn't support request without meta yet.
  # It might happen with ActionController::Live where the following code
  # will run BEFORE ActionControllerEventSubscriber.process_action is called
  if Debugbar::Current.request&.meta
    RequestBuffer.push(Debugbar::Current.pop_request!)

    # TODO: Refactor since not having ActionCable might be more common than I thought
    if defined?(ActionCable)
      ActionCable.server.broadcast("debugbar_channel", RequestBuffer.to_h)
    end
  end

  res
end