Class: Perchfall::Notify::Notifier

Inherits:
Object
  • Object
show all
Defined in:
lib/perchfall/notify/notifier.rb

Overview

Delivers a Perchfall::Report to one or more notification channels.

Notifier is the primary entry point. It accepts an array of Channel objects and calls #deliver on each one in order. All channels are attempted even if one fails; DeliveryError is raised at the end if any channel failed, with all failures captured.

Example:

slack = Perchfall::Notify::Channels::Slack.new(webhook_url: "https://...")
notifier = Perchfall::Notify::Notifier.new(channels: [slack])
notifier.notify(report)

Instance Method Summary collapse

Constructor Details

#initialize(channels:) ⇒ Notifier

Returns a new instance of Notifier.

Parameters:

  • channels (Array<Channel>) —

    one or more delivery channels

Raises:



20
21
22
23
24
# File 'lib/perchfall/notify/notifier.rb', line 20

def initialize(channels:)
  raise ConfigurationError, "at least one channel is required" if channels.empty?

  @channels = channels
end

Instance Method Details

#notify(report) ⇒ Object

Deliver the report to all configured channels.

Parameters:

  • report (Perchfall::Report)

Raises:



30
31
32
33
34
35
36
37
38
39
40
# File 'lib/perchfall/notify/notifier.rb', line 30

def notify(report)
  failures = []

  @channels.each do |channel|
    channel.deliver(report)
  rescue DeliveryError => e
    failures << e
  end

  raise_if_failed(failures)
end