Module: Mongo::Event::Publisher

Overview

This module is included for objects that need to publish events.

Since:

  • 2.0.0

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#event_listenersEvent::Listeners (readonly)

Returns event_listeners The listeners.

Returns:

Since:

  • 2.0.0



24
25
26
# File 'lib/mongo/event/publisher.rb', line 24

def event_listeners
  @event_listeners
end

Instance Method Details

#publish(event, *args) ⇒ Object

Publish the provided event.

Examples:

Publish an event.

publisher.publish("my_event", "payload")

Parameters:

  • event (String)

    The event to publish.

  • args (Array<Object>)

    The objects to pass to the listeners.

Since:

  • 2.0.0



35
36
37
38
39
# File 'lib/mongo/event/publisher.rb', line 35

def publish(event, *args)
  event_listeners.listeners_for(event).each do |listener|
    listener.handle(*args)
  end
end