Class: Faulty::Events::FilterNotifier

Inherits:
Object
  • Object
show all
Defined in:
lib/faulty/events/filter_notifier.rb

Overview

Wraps a Notifier and filters events by name

Instance Method Summary collapse

Constructor Details

#initialize(notifier, events: nil, exclude: nil) ⇒ FilterNotifier

Returns a new instance of FilterNotifier.

Parameters:

  • notifier (Notifier)

    The internal notifier to filter events for

  • events (Array, nil) (defaults to: nil)

    An array of events to allow. If nil, all EVENTS will be used

  • exclude (Array, nil) (defaults to: nil)

    An array of events to disallow. If nil, no events will be disallowed. Takes priority over events.



12
13
14
15
16
# 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

Instance Method Details

#notify(event, payload) ⇒ Object

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.



24
25
26
27
28
# File 'lib/faulty/events/filter_notifier.rb', line 24

def notify(event, payload)
  return unless @events.include?(event)

  @notifier.notify(event, payload)
end