Module: Brainguy

Defined in:
lib/brainguy.rb,
lib/brainguy/event.rb,
lib/brainguy/emitter.rb,
lib/brainguy/version.rb,
lib/brainguy/observer.rb,
lib/brainguy/observable.rb,
lib/brainguy/subscription.rb,
lib/brainguy/open_observer.rb,
lib/brainguy/basic_notifier.rb,
lib/brainguy/fluent_emitter.rb,
lib/brainguy/manifest_emitter.rb,
lib/brainguy/full_subscription.rb,
lib/brainguy/idempotent_emitter.rb,
lib/brainguy/subscription_scope.rb,
lib/brainguy/manifestly_observable.rb,
lib/brainguy/error_handling_notifier.rb,
lib/brainguy/error_collecting_notifier.rb,
lib/brainguy/single_event_subscription.rb

Overview

Namespace for the brainguy gem. See README for usage instructions.

Defined Under Namespace

Modules: Observable, Observer Classes: BasicNotifier, Emitter, ErrorCollectingNotifier, ErrorHandlingNotifier, Event, FluentEmitter, FullSubscription, IdempotentEmitter, ManifestEmitter, ManifestlyObservable, OpenObserver, SingleEventSubscription, Subscription, SubscriptionScope, UnknownEvent

Constant Summary collapse

VERSION =

The library version

"0.0.1"

Class Method Summary collapse

Class Method Details

.with_subscription_scope(source, listener_block = nil, subscription_set = IdempotentEmitter.new(source)) ⇒ Object

Execute passed block with a temporary subscription scope. See README for examples.

Parameters:

  • source

    the object initiating the event

  • listener_block (:call) (defaults to: nil)

    an optional callable that should hook up listeners

  • subscription_set (Emitter) (defaults to: IdempotentEmitter.new(source))

    an existing subscription set to layer on top of



22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/brainguy.rb', line 22

def self.with_subscription_scope(
    source,
    listener_block   = nil,
    subscription_set = IdempotentEmitter.new(source))
  subscription_set.with_subscription_scope do |scope|
    listener_block.call(scope) if listener_block
    yield scope
  end
  unless listener_block
    FluentEmitter.new(subscription_set)
  end
end