Class: Remnant::Rack

Inherits:
Object
  • Object
show all
Defined in:
lib/remnant/rack.rb

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ Rack

Returns a new instance of Rack.



3
4
5
# File 'lib/remnant/rack.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
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/remnant/rack.rb', line 7

def call(env)
  @response = [500, '', '']

  if env['REQUEST_PATH'] && env['REQUEST_PATH'].include?('/asset')
    @response = @app.call(env)
  else

    begin
      # only gc capture as dev
      if env['rack.request.cookie_hash'].is_a?(Hash) && env['rack.request.cookie_hash']['developer'] == '1'
        ::Remnant::GC.enable_stats
      end

      # record request time
      ::Remnant::Discover.measure('request') do
        @response = @app.call(env)
      end

      # collect & clear stats for next request
      ::Remnant.collect

      # only gc capture as dev
      if env['rack.request.cookie_hash'].is_a?(Hash) && env['rack.request.cookie_hash']['developer'] == '1'
        ::Remnant::GC.clear_stats
      end

      ::Rails.logger.flush if ::Rails.logger.respond_to?(:flush)
    rescue ::Exception => exception
      if defined?(Flail)
        Flail::Exception.new(env, exception).handle!
      end

      raise
    end
  end

  @response
end