Sha256: 2bd1ec28b8aac45c45368b14a71ea3a165e49f646afec67a737b1d7ea2eb4f3e

Contents?: true

Size: 858 Bytes

Versions: 2

Compression:

Stored size: 858 Bytes

Contents

require "timber/integrations/rack/middleware"

module Timber
  module Integrations
    module Rack
      # A Rack middleware that is responsible for adding the Session context
      # {Timber::Contexts::Session}.
      class SessionContext < Middleware
        def call(env)
          id = get_session_id(env)
          if id
            context = Contexts::Session.new(id: get_session_id(env))
            CurrentContext.with(context) do
              @app.call(env)
            end
          else
            @app.call(env)
          end
        end

        private
          def get_session_id(env)
            if env['rack.session']
              begin
                env['rack.session'].id
              rescue Exception
                nil
              end
            else
              nil
            end
          end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
timber-2.1.0.rc2 lib/timber/integrations/rack/session_context.rb
timber-2.1.0.rc1 lib/timber/integrations/rack/session_context.rb