Class: Stoplight::Domain::StateSnapshot

Inherits:
Data
  • Object
show all
Defined in:
lib/stoplight/domain/state_snapshot.rb,
lib/stoplight/domain/state_snapshot.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#breached_atObject

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_stateObject (readonly)

Returns the value of attribute locked_state

Returns:

  • the current value of locked_state



5
6
7
# File 'lib/stoplight/domain/state_snapshot.rb', line 5

def locked_state
  @locked_state
end

#recovery_scheduled_afterObject

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_atObject

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

#timeObject

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

#colorString

Returns one of Color::GREEN, Color::RED, or Color::YELLOW.

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

Returns:



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