Class: RailsServerMonitor::RackMiddleware

Inherits:
Object
  • Object
show all
Defined in:
app/middlewares/rails_server_monitor/rack_middleware.rb

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ RackMiddleware

Returns a new instance of RackMiddleware.



5
6
7
# File 'app/middlewares/rails_server_monitor/rack_middleware.rb', line 5

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'app/middlewares/rails_server_monitor/rack_middleware.rb', line 9

def call(env)
  request = ActionDispatch::Request.new(env)
  return @app.call(request.env) if ignore_request?(request)

  server = RailsServerMonitor::ServerSetup.new.call
  snapshot = RailsServerMonitor::TakeSnapshot.new(server)

  if snapshot.can_take_snapshot?
    snapshot.call

    RailsServerMonitor::Cleanup.new.call
  end

  @app.call(request.env)
end

#configObject



40
41
42
# File 'app/middlewares/rails_server_monitor/rack_middleware.rb', line 40

def config
  RailsServerMonitor.config
end

#ignore_request?(request) ⇒ Boolean

Returns:

  • (Boolean)


25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'app/middlewares/rails_server_monitor/rack_middleware.rb', line 25

def ignore_request?(request)
  return false if config.ignore_urls.blank?

  path = request.path
  return true if config.ignore_urls.detect do |url|
    if url.is_a?(String)
      next path == url
    elsif url.is_a?(Regexp)
      next url.match?(path)
    end
  end.present?

  false
end