class Faulty::Events::FilterNotifier

Wraps a Notifier and filters events by name

Public Class Methods

new(notifier, events: nil, exclude: nil) click to toggle source

@param notifier [Notifier] The internal notifier to filter events for @param events [Array, nil] An array of events to allow. If nil, all

{EVENTS} will be used

@param exclude [Array, nil] An array of events to disallow. If nil,

no events will be disallowed. Takes priority over `events`.
# File lib/faulty/events/filter_notifier.rb, line 12
def initialize(notifier, events: nil, exclude: nil)
  @notifier = notifier
  @events = Set.new(events || EVENTS)
  exclude&.each { |e| @events.delete(e) }
end

Public Instance Methods

notify(event, payload) click to toggle source

Notify all listeners of an event

If a listener raises an error while handling an event, that error will be captured and written to STDERR.

@param (see Notifier)

# File lib/faulty/events/filter_notifier.rb, line 24
def notify(event, payload)
  return unless @events.include?(event)

  @notifier.notify(event, payload)
end