Class: SixthSense::Guardrail::Evaluator

Inherits:
Object
  • Object
show all
Defined in:
lib/sixth_sense/guardrail/evaluator.rb

Instance Method Summary collapse

Constructor Details

#initialize(config:, baseline: Baseline.load) ⇒ Evaluator

Returns a new instance of Evaluator.



14
15
16
17
# File 'lib/sixth_sense/guardrail/evaluator.rb', line 14

def initialize(config:, baseline: Baseline.load)
  @config = config
  @baseline = baseline
end

Instance Method Details

#evaluate(reports, level:) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/sixth_sense/guardrail/evaluator.rb', line 19

def evaluate(reports, level:)
  threshold_violations = threshold_violations(reports, level: level)
  tolerance = @config.fetch(:guardrail, :tolerance, default: 1.0).to_f
  baseline_violations = ratchet? ? @baseline.violations(reports, current_level: level, tolerance: tolerance) : []
  warnings = ratchet? ? @baseline.warnings(reports, current_level: level, tolerance: tolerance) : []

  Evaluation.new(
    passed: threshold_violations.empty? && baseline_violations.empty?,
    violations: threshold_violations,
    baseline_violations: baseline_violations,
    warnings: warnings
  )
end