Class: Philiprehberger::CircuitBoard::Status
- Inherits:
-
Object
- Object
- Philiprehberger::CircuitBoard::Status
- Defined in:
- lib/philiprehberger/circuit_board/status.rb
Overview
Represents the aggregated health status of all checks.
Instance Attribute Summary collapse
-
#results ⇒ Object
readonly
Returns the value of attribute results.
Instance Method Summary collapse
-
#degraded? ⇒ Boolean
Whether the system is degraded: all critical checks pass but at least one non-critical fails.
-
#duration ⇒ Float
Total wall-clock duration (max of individual durations).
-
#healthy? ⇒ Boolean
Whether all checks passed.
-
#healthy_checks ⇒ Array<Hash>
Return check results that passed.
-
#initialize(results) ⇒ Status
constructor
A new instance of Status.
-
#to_h ⇒ Hash
Convert to a hash representation.
-
#to_json(*_args) ⇒ String
JSON representation.
-
#unhealthy_checks ⇒ Array<Hash>
Return check results that failed.
Constructor Details
#initialize(results) ⇒ Status
Returns a new instance of Status.
10 11 12 |
# File 'lib/philiprehberger/circuit_board/status.rb', line 10 def initialize(results) @results = results end |
Instance Attribute Details
#results ⇒ Object (readonly)
Returns the value of attribute results.
7 8 9 |
# File 'lib/philiprehberger/circuit_board/status.rb', line 7 def results @results end |
Instance Method Details
#degraded? ⇒ Boolean
Whether the system is degraded: all critical checks pass but at least one non-critical fails.
55 56 57 58 59 |
# File 'lib/philiprehberger/circuit_board/status.rb', line 55 def degraded? return false if healthy? critical_ok? && @results.any? { |r| !r[:healthy] } end |
#duration ⇒ Float
Total wall-clock duration (max of individual durations).
38 39 40 41 42 |
# File 'lib/philiprehberger/circuit_board/status.rb', line 38 def duration return 0.0 if @results.empty? @results.map { |r| r[:duration] || 0.0 }.max end |
#healthy? ⇒ Boolean
Whether all checks passed.
17 18 19 |
# File 'lib/philiprehberger/circuit_board/status.rb', line 17 def healthy? @results.all? { |r| r[:healthy] } end |
#healthy_checks ⇒ Array<Hash>
Return check results that passed.
31 32 33 |
# File 'lib/philiprehberger/circuit_board/status.rb', line 31 def healthy_checks @results.select { |r| r[:healthy] } end |
#to_h ⇒ Hash
Convert to a hash representation.
64 65 66 67 68 69 |
# File 'lib/philiprehberger/circuit_board/status.rb', line 64 def to_h { status: compute_status, checks: @results } end |
#to_json(*_args) ⇒ String
JSON representation.
47 48 49 50 |
# File 'lib/philiprehberger/circuit_board/status.rb', line 47 def to_json(*_args) require 'json' JSON.generate(to_h) end |
#unhealthy_checks ⇒ Array<Hash>
Return check results that failed.
24 25 26 |
# File 'lib/philiprehberger/circuit_board/status.rb', line 24 def unhealthy_checks @results.reject { |r| r[:healthy] } end |