Class: Mongo::Event::Listeners

Inherits:
Object
  • Object
show all
Defined in:
build/ruby-driver-v2.19/lib/mongo/event/listeners.rb

Overview

The queue of events getting processed in the client.

Since:

  • 2.0.0

Instance Method Summary collapse

Constructor Details

#initializeListeners

Initialize the event listeners.

Examples:

Initialize the event listeners.

Listeners.new

Since:

  • 2.0.0



32
33
34
# File 'build/ruby-driver-v2.19/lib/mongo/event/listeners.rb', line 32

def initialize
  @listeners = {}
end

Instance Method Details

#add_listener(event, listener) ⇒ Array<Object>

Add an event listener for the provided event.

Examples:

Add an event listener

publisher.add_listener("my_event", listener)

Parameters:

  • event (String)

    The event to listen for.

  • listener (Object)

    The event listener.

Returns:

  • (Array<Object>)

    The listeners for the event.

Since:

  • 2.0.0



47
48
49
# File 'build/ruby-driver-v2.19/lib/mongo/event/listeners.rb', line 47

def add_listener(event, listener)
  listeners_for(event).push(listener)
end

#listeners_for(event) ⇒ Array<Object>

Get the listeners for a specific event.

Examples:

Get the listeners.

publisher.listeners_for("test")

Parameters:

  • event (String)

    The event name.

Returns:

  • (Array<Object>)

    The listeners.

Since:

  • 2.0.0



61
62
63
# File 'build/ruby-driver-v2.19/lib/mongo/event/listeners.rb', line 61

def listeners_for(event)
  @listeners[event] ||= []
end