Sha256: 61adb9c4c132e8b27f8a01c4d94ebdabc68621ecd2da8233534515722fb7443f

Contents?: true

Size: 970 Bytes

Versions: 8

Compression:

Stored size: 970 Bytes

Contents

class TestTrack::JobSession
  def manage
    raise ArgumentError, "must provide block to `manage`" unless block_given?

    original_job_session = RequestStore[:test_track_job_session]
    RequestStore[:test_track_job_session] = self
    yield
  ensure
    notify_unsynced_assignments!
    RequestStore[:test_track_job_session] = original_job_session
  end

  def visitor_dsl_for(identity)
    raise "must be called within `manage` block" if RequestStore[:test_track_job_session].nil?

    TestTrack::VisitorDsl.new(for_identity(identity))
  end

  private

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

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

  def identity_visitor_map
    @identity_visitor_map ||= {}
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
test_track_rails_client-7.1.2 app/models/test_track/job_session.rb
test_track_rails_client-7.1.1 app/models/test_track/job_session.rb
test_track_rails_client-7.0.0 app/models/test_track/job_session.rb
test_track_rails_client-6.0.0 app/models/test_track/job_session.rb
test_track_rails_client-5.0.1 app/models/test_track/job_session.rb
test_track_rails_client-5.0.0 app/models/test_track/job_session.rb
test_track_rails_client-4.0.2 app/models/test_track/job_session.rb
test_track_rails_client-4.0.1 app/models/test_track/job_session.rb