Class: Insika::Doctor::Report
- Inherits:
-
Data
- Object
- Data
- Insika::Doctor::Report
- Defined in:
- lib/insika/doctor.rb
Overview
The outcome of a run: the findings + convenience rollups + renderers.
Instance Attribute Summary collapse
-
#findings ⇒ Object
readonly
Returns the value of attribute findings.
Instance Method Summary collapse
- #counts ⇒ Object
- #errors ⇒ Object
- #fixable ⇒ Object
- #ok? ⇒ Boolean
- #to_h ⇒ Object
-
#to_s(color: false) ⇒ Object
Human report.
- #warnings ⇒ Object
Instance Attribute Details
#findings ⇒ Object (readonly)
Returns the value of attribute findings
24 25 26 |
# File 'lib/insika/doctor.rb', line 24 def findings @findings end |
Instance Method Details
#counts ⇒ Object
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 |
#errors ⇒ Object
26 |
# File 'lib/insika/doctor.rb', line 26 def errors = findings.select(&:error?) |
#fixable ⇒ Object
28 |
# File 'lib/insika/doctor.rb', line 28 def fixable = findings.select(&:fixable?) |
#ok? ⇒ Boolean
25 |
# File 'lib/insika/doctor.rb', line 25 def ok? = errors.empty? |
#to_h ⇒ Object
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.}#{' (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 |
#warnings ⇒ Object
27 |
# File 'lib/insika/doctor.rb', line 27 def warnings = findings.select { |f| f.severity == :warn } |