Class: Smith::Doctor::Report

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeReport

Returns a new instance of Report.



8
9
10
# File 'lib/smith/doctor/report.rb', line 8

def initialize
  @checks = []
end

Instance Attribute Details

#checksObject (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_codeObject



20
21
22
# File 'lib/smith/doctor/report.rb', line 20

def exit_code
  passed? ? 0 : 1
end

#groupedObject



24
25
26
# File 'lib/smith/doctor/report.rb', line 24

def grouped
  checks.group_by { |c| c.name.split(".").first }
end

#passed?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/smith/doctor/report.rb', line 16

def passed?
  checks.none?(&:fail?)
end

#summaryObject



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