Class: Stoplight::Light

Inherits:
Object
  • Object
show all
Includes:
Runnable
Defined in:
lib/stoplight/light.rb,
lib/stoplight/light/runnable.rb

Overview

rubocop:disable Style/Documentation

Defined Under Namespace

Modules: Runnable

Class Attribute Summary collapse

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Runnable

#color, #run

Constructor Details

#initialize(name) { ... } ⇒ Light

Returns a new instance of Light

Parameters:

  • name (String)

Yields:


41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/stoplight/light.rb', line 41

def initialize(name, &code)
  @name = name
  @code = code

  @cool_off_time = Default::COOL_OFF_TIME
  @data_store = self.class.default_data_store
  @error_handler = Default::ERROR_HANDLER
  @error_notifier = self.class.default_error_notifier
  @fallback = Default::FALLBACK
  @notifiers = self.class.default_notifiers
  @threshold = Default::THRESHOLD
end

Class Attribute Details

.default_data_storeDataStore::Base

Returns:


28
29
30
# File 'lib/stoplight/light.rb', line 28

def default_data_store
  @default_data_store
end

.default_error_notifierProc

Returns:

  • (Proc)

30
31
32
# File 'lib/stoplight/light.rb', line 30

def default_error_notifier
  @default_error_notifier
end

.default_notifiersArray<Notifier::Base>

Returns:


32
33
34
# File 'lib/stoplight/light.rb', line 32

def default_notifiers
  @default_notifiers
end

Instance Attribute Details

#codeProc (readonly)

Returns:

  • (Proc)

8
9
10
# File 'lib/stoplight/light.rb', line 8

def code
  @code
end

#cool_off_timeFloat (readonly)

Returns:

  • (Float)

10
11
12
# File 'lib/stoplight/light.rb', line 10

def cool_off_time
  @cool_off_time
end

#data_storeDataStore::Base (readonly)

Returns:


12
13
14
# File 'lib/stoplight/light.rb', line 12

def data_store
  @data_store
end

#error_handlerProc (readonly)

Returns:

  • (Proc)

14
15
16
# File 'lib/stoplight/light.rb', line 14

def error_handler
  @error_handler
end

#error_notifierProc (readonly)

Returns:

  • (Proc)

16
17
18
# File 'lib/stoplight/light.rb', line 16

def error_notifier
  @error_notifier
end

#fallbackProc? (readonly)

Returns:

  • (Proc, nil)

18
19
20
# File 'lib/stoplight/light.rb', line 18

def fallback
  @fallback
end

#nameString (readonly)

Returns:

  • (String)

20
21
22
# File 'lib/stoplight/light.rb', line 20

def name
  @name
end

#notifiersArray<Notifier::Base> (readonly)

Returns:


22
23
24
# File 'lib/stoplight/light.rb', line 22

def notifiers
  @notifiers
end

#thresholdFixnum (readonly)

Returns:

  • (Fixnum)

24
25
26
# File 'lib/stoplight/light.rb', line 24

def threshold
  @threshold
end

Instance Method Details

#with_cool_off_time(cool_off_time) ⇒ self

Parameters:

  • cool_off_time (Float)

Returns:

  • (self)

56
57
58
59
# File 'lib/stoplight/light.rb', line 56

def with_cool_off_time(cool_off_time)
  @cool_off_time = cool_off_time
  self
end

#with_data_store(data_store) ⇒ self

Parameters:

Returns:

  • (self)

63
64
65
66
# File 'lib/stoplight/light.rb', line 63

def with_data_store(data_store)
  @data_store = data_store
  self
end

#with_error_handler {|error, handle| ... } ⇒ self

Yield Parameters:

  • error (Exception)
  • handle (Proc)

Returns:

  • (self)

71
72
73
74
# File 'lib/stoplight/light.rb', line 71

def with_error_handler(&error_handler)
  @error_handler = error_handler
  self
end

#with_error_notifier {|error| ... } ⇒ self

Yield Parameters:

  • error (Exception)

Returns:

  • (self)

78
79
80
81
# File 'lib/stoplight/light.rb', line 78

def with_error_notifier(&error_notifier)
  @error_notifier = error_notifier
  self
end

#with_fallback {|error| ... } ⇒ self

Yield Parameters:

  • error (Exception, nil)

Returns:

  • (self)

85
86
87
88
# File 'lib/stoplight/light.rb', line 85

def with_fallback(&fallback)
  @fallback = fallback
  self
end

#with_notifiers(notifiers) ⇒ self

Parameters:

Returns:

  • (self)

92
93
94
95
# File 'lib/stoplight/light.rb', line 92

def with_notifiers(notifiers)
  @notifiers = notifiers
  self
end

#with_threshold(threshold) ⇒ self

Parameters:

  • threshold (Fixnum)

Returns:

  • (self)

99
100
101
102
# File 'lib/stoplight/light.rb', line 99

def with_threshold(threshold)
  @threshold = threshold
  self
end