Module: Stoplight::Infrastructure::Notifier::Generic
- Defined in:
- lib/stoplight/infrastructure/notifier/generic.rb,
sig/_private/stoplight/infrastructure/notifier/generic.rbs
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 ⇒ notification_formatter
readonly
The formatter used to generate notification messages.
Instance Method Summary collapse
-
#initialize(object, formatter = nil) ⇒ Generic
A new instance of Generic.
-
#notify(light, from_color, to_color, error) ⇒ String
Sends a notification when a Stoplight changes state.
Instance Attribute Details
#formatter ⇒ notification_formatter (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) ⇒ Generic
Returns a new instance of Generic.
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) ⇒ String
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 |