Module: Stoplight::Light::Runnable

Included in:
Stoplight::Light
Defined in:
lib/stoplight/light/runnable.rb

Overview

rubocop:disable Style/Documentation

Instance Method Summary collapse

Instance Method Details

#colorString

Returns:

  • (String)

7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/stoplight/light/runnable.rb', line 7

def color
  failures, state = failures_and_state
  failure = failures.first

  if state == State::LOCKED_GREEN then Color::GREEN
  elsif state == State::LOCKED_RED then Color::RED
  elsif failures.size < threshold then Color::GREEN
  elsif failure && Time.now - failure.time >= cool_off_time
    Color::YELLOW
  else Color::RED
  end
end

#runObject

Raises:


21
22
23
24
25
26
27
# File 'lib/stoplight/light/runnable.rb', line 21

def run
  case color
  when Color::GREEN then run_green
  when Color::YELLOW then run_yellow
  else run_red
  end
end