Sha256: 37cb04700ccceeb758ea7ecfc0ee2ab0c67975b373847907a2175c2dbd27cd9e

Contents?: true

Size: 1.21 KB

Versions: 22

Compression:

Stored size: 1.21 KB

Contents

class TestTrack::SessionVisitorRepository
  attr_reader :current_identity, :unauthenticated_visitor_id

  def initialize(current_identity:, unauthenticated_visitor_id:)
    @current_identity = current_identity
    @unauthenticated_visitor_id = unauthenticated_visitor_id
  end

  def current
    if current_identity
      for_identity(current_identity)
    else
      unauthenticated
    end
  end

  def for_identity(identity)
    identity_visitor_map[identity] ||= TestTrack::LazyVisitorByIdentity.new(identity)
  end

  def forget_unauthenticated!
    @unauthenticated = TestTrack::Visitor.new
  end

  def authenticate!(identity)
    @current_identity = identity
    identity_visitor_map[identity] = unauthenticated
    unauthenticated.link_identity!(identity)
  end

  def all
    identity_visitor_map.values.to_set << current
  end

  def notify_unsynced_assignments!
    all.each do |visitor|
      if visitor.loaded? && visitor.unsynced_assignments.present?
        TestTrack::ThreadedVisitorNotifier.new(visitor).notify
      end
    end
  end

  private

  def unauthenticated
    @unauthenticated ||= TestTrack::Visitor.new(id: unauthenticated_visitor_id)
  end

  def identity_visitor_map
    @identity_visitor_map ||= {}
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
test_track_rails_client-4.0.0.alpha29 app/models/test_track/session_visitor_repository.rb
test_track_rails_client-4.0.0.alpha28 app/models/test_track/session_visitor_repository.rb
test_track_rails_client-4.0.0.alpha27 app/models/test_track/session_visitor_repository.rb
test_track_rails_client-4.0.0.alpha26 app/models/test_track/session_visitor_repository.rb
test_track_rails_client-4.0.0.alpha25 app/models/test_track/session_visitor_repository.rb
test_track_rails_client-4.0.0.alpha24 app/models/test_track/session_visitor_repository.rb
test_track_rails_client-4.0.0.alpha23 app/models/test_track/session_visitor_repository.rb
test_track_rails_client-4.0.0.alpha22 app/models/test_track/session_visitor_repository.rb
test_track_rails_client-4.0.0.alpha21 app/models/test_track/session_visitor_repository.rb
test_track_rails_client-4.0.0.alpha20 app/models/test_track/session_visitor_repository.rb
test_track_rails_client-4.0.0.alpha19 app/models/test_track/session_visitor_repository.rb
test_track_rails_client-4.0.0.alpha18 app/models/test_track/session_visitor_repository.rb
test_track_rails_client-4.0.0.alpha17 app/models/test_track/session_visitor_repository.rb
test_track_rails_client-4.0.0.alpha16 app/models/test_track/session_visitor_repository.rb
test_track_rails_client-4.0.0.alpha15 app/models/test_track/session_visitor_repository.rb
test_track_rails_client-4.0.0.alpha14 app/models/test_track/session_visitor_repository.rb
test_track_rails_client-4.0.0.alpha13 app/models/test_track/session_visitor_repository.rb
test_track_rails_client-4.0.0.alpha12 app/models/test_track/session_visitor_repository.rb
test_track_rails_client-4.0.0.alpha11 app/models/test_track/session_visitor_repository.rb
test_track_rails_client-4.0.0.alpha10 app/models/test_track/session_visitor_repository.rb