Class: Reviewer::Doctor::Report

Inherits:
Object
  • Object
show all
Defined in:
lib/reviewer/doctor/report.rb

Overview

Structured container for diagnostic findings organized by section

Defined Under Namespace

Classes: Finding

Constant Summary collapse

SECTIONS =

Ordered list of report sections

i[configuration tools opportunities environment].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeReport

Returns a new instance of Report.



21
22
23
# File 'lib/reviewer/doctor/report.rb', line 21

def initialize
  @findings = Hash.new { |hash, key| hash[key] = [] }
end

Instance Attribute Details

#findingsObject (readonly)

Returns the value of attribute findings.



19
20
21
# File 'lib/reviewer/doctor/report.rb', line 19

def findings
  @findings
end

Instance Method Details

#add(section, status:, message:, detail: nil) ⇒ Object

Adds a finding to a section

Parameters:

  • section (Symbol)

    one of SECTIONS

  • status (Symbol)

    :ok, :warning, :error, or :info

  • message (String)

    the finding summary

  • detail (String, nil) (defaults to: nil)

    optional detail text



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

def add(section, status:, message:, detail: nil)
  findings[section] << Finding.new(status: status, message: message, detail: detail)
end

#errorsObject

All error findings across sections



40
41
42
# File 'lib/reviewer/doctor/report.rb', line 40

def errors
  all_findings.select { |finding| finding.status == :error }
end

#ok?Boolean

Whether all findings are free of errors

Returns:

  • (Boolean)


35
36
37
# File 'lib/reviewer/doctor/report.rb', line 35

def ok?
  all_findings.none? { |finding| finding.status == :error }
end

#section(name) ⇒ Array<Finding>

Findings for a specific section

Parameters:

  • name (Symbol)

    the section name

Returns:

  • (Array<Finding>)

    findings for that section



52
53
54
# File 'lib/reviewer/doctor/report.rb', line 52

def section(name)
  findings[name]
end

#warningsObject

All warning findings across sections



45
46
47
# File 'lib/reviewer/doctor/report.rb', line 45

def warnings
  all_findings.select { |finding| finding.status == :warning }
end