Class: Henitai::CompositeProgressReporter

Inherits:
Object
  • Object
show all
Defined in:
lib/henitai/composite_progress_reporter.rb,
sig/henitai.rbs

Overview

Fans a single #progress callback out to several observers so the execution engines keep exactly one progress hook. Used to run the terminal reporter and the checkpoint writer side by side.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(reporters) ⇒ CompositeProgressReporter

Returns a new instance of CompositeProgressReporter.

Parameters:

  • (Array[untyped])


34
35
36
# File 'lib/henitai/composite_progress_reporter.rb', line 34

def initialize(reporters)
  @reporters = reporters.compact
end

Class Method Details

.checkpoint_for(config, source_provider, full_run) ⇒ Object



23
24
25
26
27
28
# File 'lib/henitai/composite_progress_reporter.rb', line 23

def self.checkpoint_for(config, source_provider, full_run)
  return unless config.respond_to?(:checkpoint_enabled) && config.checkpoint_enabled
  return unless reporter?(config, "json") || reporter?(config, "html")

  CheckpointReporter.new(config:, source_provider:, authoritative: full_run)
end

.for(config:, source_provider:, full_run:) ⇒ Object?

Assembles the active progress reporters for a run: the terminal reporter when terminal output is on, and the checkpoint writer when enabled and a file report (json/html) is configured. Returns a single reporter when only one is active, the composite when several are, or nil when none are.

Parameters:

  • config: (Object)
  • source_provider: (Object)
  • full_run: (Boolean)

Returns:

  • (Object, nil)


12
13
14
15
16
17
# File 'lib/henitai/composite_progress_reporter.rb', line 12

def self.for(config:, source_provider:, full_run:)
  active = [terminal_for(config), checkpoint_for(config, source_provider, full_run)].compact
  return active.first if active.one?

  active.empty? ? nil : new(active)
end

.reporter?(config, name) ⇒ Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/henitai/composite_progress_reporter.rb', line 30

def self.reporter?(config, name)
  Array(config.reporters).map(&:to_s).include?(name)
end

.terminal_for(config) ⇒ Object



19
20
21
# File 'lib/henitai/composite_progress_reporter.rb', line 19

def self.terminal_for(config)
  Reporter::Terminal.new(config:) if reporter?(config, "terminal")
end

Instance Method Details

#progress(mutant, scenario_result: nil) ⇒ void

This method returns an undefined value.

Parameters:

  • (Object)
  • scenario_result: (Object) (defaults to: nil)


38
39
40
# File 'lib/henitai/composite_progress_reporter.rb', line 38

def progress(mutant, scenario_result: nil)
  @reporters.each { |reporter| reporter.progress(mutant, scenario_result:) }
end