Class: Wurk::Preflight::Report
- Inherits:
-
Object
- Object
- Wurk::Preflight::Report
- Defined in:
- lib/wurk/preflight/report.rb
Overview
What a run found. warning findings decide the exit status; info findings
are facts an operator should see that do not by themselves mean trouble.
Defined Under Namespace
Classes: Finding
Constant Summary collapse
- CLEAN =
0- FINDINGS =
1- LABELS =
{ warning: 'WARN', info: 'info' }.freeze
- APP_CODE_RAN =
'app_code_ran'
Instance Attribute Summary collapse
-
#findings ⇒ Object
readonly
Returns the value of attribute findings.
-
#sections ⇒ Object
readonly
Returns the value of attribute sections.
Instance Method Summary collapse
- #exit_status ⇒ Object
- #info(code, message) ⇒ Object
-
#initialize(command) ⇒ Report
constructor
A new instance of Report.
- #section(name, data) ⇒ Object
-
#target(reader, keyspace) ⇒ Object
Which Redis this verdict is about, first in the report.
- #to_h ⇒ Object
- #to_json ⇒ Object
- #to_text ⇒ Object
- #warning(code, message) ⇒ Object
Constructor Details
#initialize(command) ⇒ Report
Returns a new instance of Report.
19 20 21 22 23 |
# File 'lib/wurk/preflight/report.rb', line 19 def initialize(command) @command = command @findings = [] @sections = {} end |
Instance Attribute Details
#findings ⇒ Object (readonly)
Returns the value of attribute findings.
17 18 19 |
# File 'lib/wurk/preflight/report.rb', line 17 def findings @findings end |
#sections ⇒ Object (readonly)
Returns the value of attribute sections.
17 18 19 |
# File 'lib/wurk/preflight/report.rb', line 17 def sections @sections end |
Instance Method Details
#exit_status ⇒ Object
40 |
# File 'lib/wurk/preflight/report.rb', line 40 def exit_status = @findings.any? { |finding| finding.severity == :warning } ? FINDINGS : CLEAN |
#info(code, message) ⇒ Object
26 |
# File 'lib/wurk/preflight/report.rb', line 26 def info(code, ) = @findings << Finding.new(:info, code, ) |
#section(name, data) ⇒ Object
27 |
# File 'lib/wurk/preflight/report.rb', line 27 def section(name, data) = @sections[name] = data |
#target(reader, keyspace) ⇒ Object
Which Redis this verdict is about, first in the report. An empty keyspace is far likelier a wrong URL or DB than a real Redis with nothing in it.
31 32 33 34 35 36 37 38 |
# File 'lib/wurk/preflight/report.rb', line 31 def target(reader, keyspace) place = reader.target section('target', place) return unless keyspace.scanned.zero? warning('empty_keyspace', "No keys in #{::JSON.generate(place)}. A Redis with a live fleet is never empty: " \ 'check this is the right URL and DB.') end |
#to_h ⇒ Object
42 43 44 45 |
# File 'lib/wurk/preflight/report.rb', line 42 def to_h scrub({ 'command' => @command, 'status' => exit_status.zero? ? 'clean' : 'findings', 'sections' => @sections, 'findings' => @findings.map { |f| finding_row(f) } }) end |
#to_json ⇒ Object
47 |
# File 'lib/wurk/preflight/report.rb', line 47 def to_json(*) = ::JSON.pretty_generate(to_h) |
#to_text ⇒ Object
49 50 51 52 53 |
# File 'lib/wurk/preflight/report.rb', line 49 def to_text ordered = @findings.sort_by { |f| f.severity == :warning ? 0 : 1 } [*scrub(@sections).map { |name, data| "#{name}: #{::JSON.generate(data)}" }, '', *ordered.map { |f| scrub(line_for(f)) }, '', summary].join("\n") end |