Module: Brainguy::Observable

Extended by:
Forwardable
Defined in:
lib/brainguy/observable.rb

Overview

A convenience module for making client classes observable.

Instance Method Summary collapse

Instance Method Details

#eventsEmitter

Returns the Emitter managing all subscriptions to this object's events.

Returns:

  • (Emitter)

    the Emitter managing all subscriptions to this object's events.



11
12
13
# File 'lib/brainguy/observable.rb', line 11

def events
  @brainguy_subscriptions ||= Emitter.new(self)
end

#on(name_or_handlers, &block) ⇒ Object

(see Emitter#on)



26
# File 'lib/brainguy/observable.rb', line 26

def_delegator :events, :on

#with_subscription_scope(listener_block, &block) ⇒ Object

Create a temporary scope for transient subscriptions. Useful for making a single method listenable. See README for usage examples.

Parameters:

  • listener_block (:call)

    an optional callable that should hook up listeners



20
21
22
# File 'lib/brainguy/observable.rb', line 20

def with_subscription_scope(listener_block, &block)
  Brainguy.with_subscription_scope(self, listener_block, events, &block)
end