Sha256: 34d44b5950374c1b87d8167543a09d25cc3ede301e852bae9b5f7dc44b75be40

Contents?: true

Size: 969 Bytes

Versions: 25

Compression:

Stored size: 969 Bytes

Contents

require 'singleton'

module Mongo
  class Client
    alias :get_session_without_tracking :get_session

    def get_session(options = {})
      get_session_without_tracking(options).tap do |session|
        SessionRegistry.instance.register(session)
      end
    end
  end

  class Session
    alias :end_session_without_tracking :end_session

    def end_session
      SessionRegistry.instance.unregister(self)
      end_session_without_tracking
    end
  end
end


class SessionRegistry
  include Singleton

  def initialize
    @registry = {}
  end

  def register(session)
    @registry[session.session_id] = session if session
  end

  def unregister(session)
    @registry.delete(session.session_id)
  end

  def verify_sessions_ended!
    unless @registry.empty?
      sessions = @registry.map { |_, session| session }
      raise "Session registry contains live sessions: #{sessions.join(', ')}"
    end
  end

  def clear_registry
    @registry = {}
  end
end

Version data entries

25 entries across 25 versions & 2 rubygems

Version Path
mongoid-7.3.4 spec/support/session_registry.rb
mongoid-7.1.11 spec/support/session_registry.rb
mongoid-7.2.6 spec/support/session_registry.rb
mongoid-7.3.3 spec/support/session_registry.rb
mongoid-7.3.2 spec/support/session_registry.rb
mongoid-7.2.5 spec/support/session_registry.rb
mongoid-7.1.10 spec/support/session_registry.rb
mongoid-7.1.9 spec/support/session_registry.rb
mongoid-7.2.4 spec/support/session_registry.rb
mongoid-7.3.1 spec/support/session_registry.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/mongoid-7.1.7/spec/support/session_registry.rb
mongoid-7.3.0 spec/support/session_registry.rb
mongoid-7.2.3 spec/support/session_registry.rb
mongoid-7.1.8 spec/support/session_registry.rb
mongoid-7.0.13 spec/support/session_registry.rb
mongoid-7.2.2 spec/support/session_registry.rb
mongoid-7.2.1 spec/support/session_registry.rb
mongoid-7.1.7 spec/support/session_registry.rb
mongoid-7.0.12 spec/support/session_registry.rb
mongoid-7.2.0 spec/support/session_registry.rb