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: ConfiguredTool, Discovery, Environment, Finding, Observation

Constant Summary collapse

SECTIONS =

Ordered list of report sections

%i[configuration configured_tools discoveries environment].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeReport



57
58
59
60
61
62
63
# File 'lib/reviewer/doctor/report.rb', line 57

def initialize
  @findings = Hash.new { |hash, key| hash[key] = [] }
  @configured_tools = []
  @discoveries = []
  @environment = []
  @configuration_state = :unknown
end

Instance Attribute Details

#configuration_pathObject (readonly)

Returns the value of attribute configuration_path.



54
55
56
# File 'lib/reviewer/doctor/report.rb', line 54

def configuration_path
  @configuration_path
end

#configuration_stateObject (readonly)

Returns the value of attribute configuration_state.



54
55
56
# File 'lib/reviewer/doctor/report.rb', line 54

def configuration_state
  @configuration_state
end

#configured_toolsObject (readonly)

Returns the value of attribute configured_tools.



54
55
56
# File 'lib/reviewer/doctor/report.rb', line 54

def configured_tools
  @configured_tools
end

#discoveriesObject (readonly)

Returns the value of attribute discoveries.



54
55
56
# File 'lib/reviewer/doctor/report.rb', line 54

def discoveries
  @discoveries
end

#environmentObject (readonly)

Returns the value of attribute environment.



54
55
56
# File 'lib/reviewer/doctor/report.rb', line 54

def environment
  @environment
end

#findingsObject (readonly)

Returns the value of attribute findings.



54
55
56
# File 'lib/reviewer/doctor/report.rb', line 54

def findings
  @findings
end

Instance Method Details

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

Adds a finding to a section



70
71
72
# File 'lib/reviewer/doctor/report.rb', line 70

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

#add_configured_tool(key:, name:, skip_in_batch:, commands:, files:, source:) ⇒ Object



105
106
107
108
109
110
111
112
113
114
# File 'lib/reviewer/doctor/report.rb', line 105

def add_configured_tool(key:, name:, skip_in_batch:, commands:, files:, source:)
  configured_tools << ConfiguredTool.new(
    key: key,
    name: name,
    skip_in_batch: skip_in_batch,
    commands: commands,
    files: files,
    source: source
  )
end

#add_discovery(key:, name:, observations:) ⇒ Object



116
117
118
# File 'lib/reviewer/doctor/report.rb', line 116

def add_discovery(key:, name:, observations:)
  discoveries << Discovery.new(key: key, name: name, observations: observations)
end

#add_environment(name:, status:, value:, detail: nil) ⇒ Object



120
121
122
# File 'lib/reviewer/doctor/report.rb', line 120

def add_environment(name:, status:, value:, detail: nil)
  environment << Environment.new(name: name, status: status, value: value, detail: detail)
end

#errorsObject

All error findings across sections



80
81
82
# File 'lib/reviewer/doctor/report.rb', line 80

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

#ok?Boolean

Whether all findings are free of errors



75
76
77
# File 'lib/reviewer/doctor/report.rb', line 75

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

#section(name) ⇒ Array<Finding>

Findings for a specific section



92
93
94
95
96
97
98
# File 'lib/reviewer/doctor/report.rb', line 92

def section(name)
  return configured_tools if name == :configured_tools
  return discoveries if name == :discoveries
  return environment if name == :environment

  findings[name]
end

#set_configuration(path:, state:) ⇒ Object



100
101
102
103
# File 'lib/reviewer/doctor/report.rb', line 100

def set_configuration(path:, state:)
  @configuration_path = path
  @configuration_state = state
end

#to_hObject



124
125
126
127
128
129
130
131
132
133
134
135
136
137
# File 'lib/reviewer/doctor/report.rb', line 124

def to_h
  {
    schema_version: 1,
    configuration: {
      path: configuration_path,
      state: configuration_state,
      findings: section(:configuration).map(&:to_h)
    },
    configured_tools: configured_tools.map(&:to_h),
    discoveries: discoveries.map(&:to_h),
    environment: environment.map(&:to_h),
    summary: summary
  }
end

#warningsObject

All warning findings across sections



85
86
87
# File 'lib/reviewer/doctor/report.rb', line 85

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