Class: Realm::HealthStatus
- Inherits:
-
Object
- Object
- Realm::HealthStatus
- Defined in:
- lib/realm/health_status.rb
Constant Summary collapse
- CODES =
%i[green yellow red].freeze
Instance Attribute Summary collapse
-
#code ⇒ Object
readonly
Returns the value of attribute code.
-
#issues ⇒ Object
readonly
Returns the value of attribute issues.
Class Method Summary collapse
Instance Method Summary collapse
Instance Attribute Details
#code ⇒ Object (readonly)
Returns the value of attribute code.
6 7 8 |
# File 'lib/realm/health_status.rb', line 6 def code @code end |
#issues ⇒ Object (readonly)
Returns the value of attribute issues.
6 7 8 |
# File 'lib/realm/health_status.rb', line 6 def issues @issues end |
Class Method Details
.[](code, *issues) ⇒ Object
9 10 11 |
# File 'lib/realm/health_status.rb', line 9 def [](code, *issues) new(code, issues.flatten) end |
.combine(component_map) ⇒ Object
17 18 19 20 |
# File 'lib/realm/health_status.rb', line 17 def combine(component_map) code_index = component_map.values.map { |i| CODES.index(i.code) }.max new(CODES[code_index || 0], [], component_map) end |
.from_issues(issues) ⇒ Object
13 14 15 |
# File 'lib/realm/health_status.rb', line 13 def from_issues(issues) new(issues.blank? ? :green : :red, issues) end |
Instance Method Details
#for_component(*names) ⇒ Object
23 24 25 |
# File 'lib/realm/health_status.rb', line 23 def for_component(*names) @component_map.dig(*names) end |
#to_h ⇒ Object
27 28 29 30 31 32 |
# File 'lib/realm/health_status.rb', line 27 def to_h hash = { status: @code } hash[:issues] = @issues if @issues.present? hash[:components] = @component_map.transform_values(&:to_h) if @component_map.present? hash end |