Class: Brainguy::FluentEmitter

Inherits:
Emitter
  • Object
show all
Defined in:
lib/brainguy/fluent_emitter.rb

Overview

A wrapper for a Emitter that enables a "fluent API" by returning self from each method.

Examples:

Enables code like this:


kitten.on(:purr) do
  # handle purr...
end.on(:mew) do
  # handle mew...
end

Constant Summary

Constants inherited from Emitter

Emitter::DEFAULT_NOTIFIER

Instance Method Summary collapse

Methods inherited from Emitter

#detach, #emit, #initialize, new_from_existing, #subscriptions, #with_subscription_scope

Constructor Details

This class inherits a constructor from Brainguy::Emitter

Instance Method Details

#attachSubscription

Attach a new object to listen for events. A listener is expected to be call-able, and it will receive the #call message with an Event each time one is emitted.


25
26
27
28
# File 'lib/brainguy/fluent_emitter.rb', line 25

def attach(*)
  super
  self
end

#on(name, &block) ⇒ Object #on(handlers) ⇒ Object

Attach blocks of code to handle specific named events.

Overloads:

  • #on(name, &block) ⇒ Object

    Attach a block to be called for a specific event. The block will be called with the event arguments (not the event object).

  • #on(handlers) ⇒ Object

    Attach multiple event-specific handlers at once.


18
19
20
21
# File 'lib/brainguy/fluent_emitter.rb', line 18

def on(*)
  super
  self
end