Class: Stoplight::Domain::StateSnapshot
- Inherits:
-
Data
- Object
- Data
- Stoplight::Domain::StateSnapshot
- Defined in:
- lib/stoplight/domain/state_snapshot.rb,
lib/stoplight/domain/state_snapshot.rb
Instance Attribute Summary collapse
-
#breached_at ⇒ Object
The time when the light became red (breached threshold).
-
#locked_state ⇒ Object
readonly
Returns the value of attribute locked_state.
-
#recovery_scheduled_after ⇒ Object
When Light transitions to RED, it schedules recovery after the Cool Off Time.
-
#recovery_started_at ⇒ Object
When in YELLOW state, this time indicates the time of transitioning to YELLOW.
-
#time ⇒ Object
The time when the snapshot was taken.
Instance Method Summary collapse
-
#color ⇒ String
One of
Color::GREEN,Color::RED, orColor::YELLOW. - #recovery_scheduled_after! ⇒ Object
-
#recovery_started? ⇒ Boolean
YELLOW color could be entered implicitly through a timeout and explicitly through a transition.
- #recovery_started_at! ⇒ Object
Instance Attribute Details
#breached_at ⇒ Object
The time when the light became red (breached threshold)
14 15 16 |
# File 'lib/stoplight/domain/state_snapshot.rb', line 14 def breached_at @breached_at end |
#locked_state ⇒ Object (readonly)
Returns the value of attribute locked_state
5 6 7 |
# File 'lib/stoplight/domain/state_snapshot.rb', line 5 def locked_state @locked_state end |
#recovery_scheduled_after ⇒ Object
When Light transitions to RED, it schedules recovery after the Cool Off Time.
14 15 16 |
# File 'lib/stoplight/domain/state_snapshot.rb', line 14 def recovery_scheduled_after @recovery_scheduled_after end |
#recovery_started_at ⇒ Object
When in YELLOW state, this time indicates the time of transitioning to YELLOW
14 15 16 |
# File 'lib/stoplight/domain/state_snapshot.rb', line 14 def recovery_started_at @recovery_started_at end |
#time ⇒ Object
The time when the snapshot was taken
14 15 16 |
# File 'lib/stoplight/domain/state_snapshot.rb', line 14 def time @time end |
Instance Method Details
#color ⇒ String
Returns one of Color::GREEN, Color::RED, or Color::YELLOW.
27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/stoplight/domain/state_snapshot.rb', line 27 def color if locked_state == State::LOCKED_GREEN Color::GREEN elsif locked_state == State::LOCKED_RED Color::RED elsif (recovery_scheduled_after && recovery_scheduled_after! < time) || recovery_started_at Color::YELLOW elsif breached_at Color::RED else Color::GREEN end end |
#recovery_scheduled_after! ⇒ Object
58 59 60 |
# File 'lib/stoplight/domain/state_snapshot.rb', line 58 def recovery_scheduled_after! recovery_scheduled_after or raise TypeError, "recovery_scheduled_after must not be nil" end |
#recovery_started? ⇒ Boolean
YELLOW color could be entered implicitly through a timeout and explicitly through a transition.
This method indicates whether the recovery has already started explicitly
46 47 48 49 50 51 52 |
# File 'lib/stoplight/domain/state_snapshot.rb', line 46 def recovery_started? if recovery_started_at.nil? false else recovery_started_at! <= time end end |
#recovery_started_at! ⇒ Object
54 55 56 |
# File 'lib/stoplight/domain/state_snapshot.rb', line 54 def recovery_started_at! recovery_started_at or raise TypeError, "recovery_started_at must not be nil" end |