Module: Mongo::Event::Publisher

Included in:
Server, Server::Monitor
Defined in:
lib/mongo/event/publisher.rb

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



27
28
29
# File 'lib/mongo/event/publisher.rb', line 27

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



38
39
40
41
42
# File 'lib/mongo/event/publisher.rb', line 38

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