Sha256: ad935f0bb8f564e23959c3626490ab29b6aaae624c3e6f9bee1ae84aa440b904

Contents?: true

Size: 1.1 KB

Versions: 10

Compression:

Stored size: 1.1 KB

Contents

# frozen_string_literal: true

require 'appmap/handler'

module AppMap
  module Handler
    module Rails
      # Context of a rails request tracking.
      # Mostly a utility class to clean up and deduplicate request handler code.
      class Context
        def initialize(environment = nil)
          environment[REQUEST_CONTEXT] = self if environment
          @thread = Thread.current
        end

        def self.from(environment)
          environment[REQUEST_CONTEXT]
        end

        def self.create(environment)
          return if from environment

          new environment
        end

        def self.remove(env)
          env[REQUEST_CONTEXT] = nil
        end

        def find_template_render_value
          @thread[TEMPLATE_RENDER_VALUE].tap do
            @thread[TEMPLATE_RENDER_VALUE] = nil
          end
        end

        # context is set on the rack environment to make sure a single request is only recorded once
        # even if ActionDispatch::Executor is entered more than once (as can happen with engines)
        REQUEST_CONTEXT = 'appmap.handler.request.context'
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
appmap-1.1.1 lib/appmap/handler/rails/context.rb
appmap-1.0.1 lib/appmap/handler/rails/context.rb
appmap-1.0.0 lib/appmap/handler/rails/context.rb
appmap-0.103.0 lib/appmap/handler/rails/context.rb
appmap-0.102.2 lib/appmap/handler/rails/context.rb
appmap-0.102.1 lib/appmap/handler/rails/context.rb
appmap-0.102.0 lib/appmap/handler/rails/context.rb
appmap-0.101.0 lib/appmap/handler/rails/context.rb
appmap-0.100.0 lib/appmap/handler/rails/context.rb
appmap-0.99.4 lib/appmap/handler/rails/context.rb