Class: LitmusPaper::Health
- Inherits:
-
Object
- Object
- LitmusPaper::Health
- Defined in:
- lib/litmus_paper/health.rb
Instance Attribute Summary collapse
-
#forced_reason ⇒ Object
readonly
Returns the value of attribute forced_reason.
-
#summary ⇒ Object
readonly
Returns the value of attribute summary.
Instance Method Summary collapse
- #direction ⇒ Object
- #ensure(dependency) ⇒ Object
- #forced? ⇒ Boolean
-
#initialize(forced = :none, forced_reason = "") ⇒ Health
constructor
A new instance of Health.
- #measured_health ⇒ Object
- #ok? ⇒ Boolean
- #perform(metric) ⇒ Object
- #value ⇒ Object
Constructor Details
#initialize(forced = :none, forced_reason = "") ⇒ Health
Returns a new instance of Health.
6 7 8 9 10 11 12 |
# File 'lib/litmus_paper/health.rb', line 6 def initialize(forced = :none, forced_reason = "") @value = 0 @dependencies_available = true @summary = "" @forced = forced @forced_reason = forced_reason end |
Instance Attribute Details
#forced_reason ⇒ Object (readonly)
Returns the value of attribute forced_reason.
4 5 6 |
# File 'lib/litmus_paper/health.rb', line 4 def forced_reason @forced_reason end |
#summary ⇒ Object (readonly)
Returns the value of attribute summary.
4 5 6 |
# File 'lib/litmus_paper/health.rb', line 4 def summary @summary end |
Instance Method Details
#direction ⇒ Object
22 23 24 |
# File 'lib/litmus_paper/health.rb', line 22 def direction @forced end |
#ensure(dependency) ⇒ Object
58 59 60 61 62 63 |
# File 'lib/litmus_paper/health.rb', line 58 def ensure(dependency) available = dependency.available? @dependencies_available &&= available @summary << "#{dependency}: #{available ? 'OK' : 'FAIL'}\n" end |
#forced? ⇒ Boolean
18 19 20 |
# File 'lib/litmus_paper/health.rb', line 18 def forced? @forced != :none end |
#measured_health ⇒ Object
46 47 48 49 |
# File 'lib/litmus_paper/health.rb', line 46 def measured_health return 0 unless @dependencies_available @value end |
#ok? ⇒ Boolean
14 15 16 |
# File 'lib/litmus_paper/health.rb', line 14 def ok? value > 0 end |
#perform(metric) ⇒ Object
51 52 53 54 55 56 |
# File 'lib/litmus_paper/health.rb', line 51 def perform(metric) health = metric.current_health.ceil @value += health @summary << "#{metric}: #{health}\n" end |
#value ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/litmus_paper/health.rb', line 26 def value if forced? return case @forced when :up 100 when :down 0 when :health forced_health = @forced_reason.split("\n").last.to_i # This could potentially be argued differently, but I feel like forcing # a health value != forcing up - if the measured health is less than the # forced health, we should return the measured health. measured_health < forced_health ? measured_health : forced_health end end measured_health end |