Sha256: 1ff576ee33a950aa998b86b926e34a8ba74cc207ee3e19810012353123c185ee

Contents?: true

Size: 745 Bytes

Versions: 2

Compression:

Stored size: 745 Bytes

Contents

# frozen_string_literal: true

require 'securerandom'

module BigSession
  # SessionId object bridges an access from users to session id
  class SessionId
    class << self
      def with_session_id(session_id, &_block)
        container.push(session_id)
        yield
      ensure
        container.pop
      end

      def current
        container.last
      end

=begin
      def set(value = nil)
        Thread.current[::BigSession::THREAD_BIG_SESSION_ID_KEY] =
          value || new_session_id
      end
=end

      def new_session_id
        SecureRandom.hex(16)
      end

      def container
        Thread.current[::BigSession::THREAD_BIG_SESSION_CONTAINER_KEY] ||= []
      end
    end

    private_class_method :container
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
big_session-0.1.2 lib/big_session/session_id.rb
big_session-0.1.1 lib/big_session/session_id.rb