Sha256: 945447159d5b172f9a7671b2ccbfd2b3504c8e72fe1152833501ff66b47832cf

Contents?: true

Size: 1.13 KB

Versions: 3

Compression:

Stored size: 1.13 KB

Contents

class Remnant
  class Rack
    def initialize(app)
      @app = app
    end

    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
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
remnant-1.0.0 lib/remnant/rack.rb
remnant-0.9.5 lib/remnant/rack.rb
remnant-0.9.4 lib/remnant/rack.rb