Class: Insika::Doctor::Report

Inherits:
Data
  • Object
show all
Defined in:
lib/insika/doctor.rb

Overview

The outcome of a run: the findings + convenience rollups + renderers.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#findingsObject (readonly)

Returns the value of attribute findings

Returns:

  • (Object)

    the current value of findings



24
25
26
# File 'lib/insika/doctor.rb', line 24

def findings
  @findings
end

Instance Method Details

#countsObject



34
35
36
# File 'lib/insika/doctor.rb', line 34

def counts
  findings.each_with_object(Hash.new(0)) { |f, acc| acc[f.severity.to_s] += 1 }
end

#errorsObject



26
# File 'lib/insika/doctor.rb', line 26

def errors   = findings.select(&:error?)

#fixableObject



28
# File 'lib/insika/doctor.rb', line 28

def fixable  = findings.select(&:fixable?)

#ok?Boolean

Returns:

  • (Boolean)


25
# File 'lib/insika/doctor.rb', line 25

def ok? = errors.empty?

#to_hObject



30
31
32
# File 'lib/insika/doctor.rb', line 30

def to_h
  { "ok" => ok?, "counts" => counts, "findings" => findings.map(&:to_h) }
end

#to_s(color: false) ⇒ Object

Human report. color wraps severities in ANSI when the sink is a TTY.



39
40
41
42
43
44
45
46
47
# File 'lib/insika/doctor.rb', line 39

def to_s(color: false)
  lines = findings.map { |f| "#{glyph(f.severity, color)} [#{f.check}] #{f.message}#{' (fixable)' if f.fixable?}" }
  summary =
    if ok? && warnings.empty? then "config OK"
    elsif ok? then "config OK — #{warnings.length} warning(s)"
    else "#{errors.length} error(s), #{warnings.length} warning(s)"
    end
  (lines + ["", summary]).join("\n")
end

#warningsObject



27
# File 'lib/insika/doctor.rb', line 27

def warnings = findings.select { |f| f.severity == :warn }