module SimpleCov::ParallelAdapters

def adapters

specific match.
downstream code can override the built-ins by registering a more
are prepended (#register puts new entries at the front) so
GenericAdapter as the env-var fallback. User-registered adapters
specific — uses the gem's own API when the gem is loaded); then
Adapters in selection order. ParallelTestsAdapter first (most
def adapters
  @adapters ||= [ParallelTestsAdapter, GenericAdapter]
end

def current

process as single-worker.
parallel test runner), in which case the caller should treat the
no adapter is active (i.e., we're not running under any recognized
registered adapter whose `active?` returns true. Returns nil when
The adapter SimpleCov should consult for this process — the first
def current
  return @current if defined?(@current)
  @current = adapters.find(&:active?)
end

def register(adapter)

SimpleCov::ParallelAdapters.register MyRunnerAdapter

end
def self.expected_worker_count = ENV["MY_RUNNER_WORKERS"].to_i
def self.first_worker? = ENV["MY_RUNNER_PID"].to_i == 1
def self.active? = ENV["MY_RUNNER_PID"]
class MyRunnerAdapter < SimpleCov::ParallelAdapters::Base

and Generic adapters.
specific runner takes precedence over the built-in ParallelTests
at the front of the selection list so a custom adapter for a
Register a custom adapter. Newly registered adapters are inserted
def register(adapter)
  reset_current!
  adapters.unshift(adapter) unless adapters.include?(adapter)
  adapter
end

def reset_current!

mutate env vars between examples; production runs are single-shot.
Clear the memoized `current` selection. Primarily for tests that
def reset_current!
  remove_instance_variable(:@current) if defined?(@current)
end