Module: Stoplight::Infrastructure::Notifier::Generic
Overview
The Generic module provides a reusable implementation for notifiers in Stoplight. It includes a formatter for generating notification messages and defines the notify method.
Constant Summary collapse
- DEFAULT_FORMATTER =
lambda do |light, from_color, to_color, error| words = ["Switching", light.name, "from", from_color, "to", to_color] words += ["because", error.class, error.] if error words.join(" ") end
Instance Attribute Summary collapse
-
#formatter ⇒ Object
readonly
The formatter used to generate notification messages.
Instance Method Summary collapse
- #initialize(object, formatter = nil) ⇒ Object
-
#notify(light, from_color, to_color, error) ⇒ Object
Sends a notification when a Stoplight changes state.
Instance Attribute Details
#formatter ⇒ Object (readonly)
The formatter used to generate notification messages.
44 45 46 |
# File 'lib/stoplight/infrastructure/notifier/generic.rb', line 44 def formatter @formatter end |
Instance Method Details
#initialize(object, formatter = nil) ⇒ Object
56 57 58 59 |
# File 'lib/stoplight/infrastructure/notifier/generic.rb', line 56 def initialize(object, formatter = nil) @object = object @formatter = formatter || DEFAULT_FORMATTER end |
#notify(light, from_color, to_color, error) ⇒ Object
Sends a notification when a Stoplight changes state.
62 63 64 65 66 |
# File 'lib/stoplight/infrastructure/notifier/generic.rb', line 62 def notify(light, from_color, to_color, error) = formatter.call(light, from_color, to_color, error) put() end |