Class: Smith::Doctor::Report
- Inherits:
-
Object
- Object
- Smith::Doctor::Report
- Defined in:
- lib/smith/doctor/report.rb
Instance Attribute Summary collapse
-
#checks ⇒ Object
readonly
Returns the value of attribute checks.
Instance Method Summary collapse
- #add(name:, status:, message:, detail: nil) ⇒ Object
- #exit_code ⇒ Object
- #grouped ⇒ Object
-
#initialize ⇒ Report
constructor
A new instance of Report.
- #passed? ⇒ Boolean
- #summary ⇒ Object
Constructor Details
#initialize ⇒ Report
Returns a new instance of Report.
8 9 10 |
# File 'lib/smith/doctor/report.rb', line 8 def initialize @checks = [] end |
Instance Attribute Details
#checks ⇒ Object (readonly)
Returns the value of attribute checks.
6 7 8 |
# File 'lib/smith/doctor/report.rb', line 6 def checks @checks end |
Instance Method Details
#add(name:, status:, message:, detail: nil) ⇒ Object
12 13 14 |
# File 'lib/smith/doctor/report.rb', line 12 def add(name:, status:, message:, detail: nil) @checks << Check.new(name:, status:, message:, detail:) end |
#exit_code ⇒ Object
20 21 22 |
# File 'lib/smith/doctor/report.rb', line 20 def exit_code passed? ? 0 : 1 end |
#grouped ⇒ Object
24 25 26 |
# File 'lib/smith/doctor/report.rb', line 24 def grouped checks.group_by { |c| c.name.split(".").first } end |
#passed? ⇒ Boolean
16 17 18 |
# File 'lib/smith/doctor/report.rb', line 16 def passed? checks.none?(&:fail?) end |
#summary ⇒ Object
28 29 30 31 32 33 34 35 36 |
# File 'lib/smith/doctor/report.rb', line 28 def summary counts = checks.group_by(&:status).transform_values(&:size) parts = [] parts << "#{counts.fetch(:pass, 0)} passed" parts << "#{counts[:warn]} warnings" if counts[:warn] parts << "#{counts[:fail]} failed" if counts[:fail] parts << "#{counts[:skip]} skipped" if counts[:skip] parts.join(", ") end |