Module: Downstream

Defined in:
lib/downstream.rb,
lib/downstream/event.rb,
lib/downstream/config.rb,
lib/downstream/engine.rb,
lib/downstream/version.rb,
lib/downstream/data_event.rb,
lib/downstream/subscriber.rb,
lib/downstream/subscriber_job.rb,
lib/downstream/rspec/have_published_event.rb,
lib/downstream/pubsub_adapters/abstract_pubsub.rb,
lib/downstream/pubsub_adapters/stateless/pubsub.rb,
lib/downstream/pubsub_adapters/stateless/subscriber.rb,
lib/downstream/rspec/have_enqueued_async_subscriber_for.rb

Defined Under Namespace

Modules: Stateless Classes: AbstractPubsub, Config, DataEvent, Engine, Event, HaveEnqueuedAsyncSubscriberFor, HavePublishedEvent, Subscriber, SubscriberJob

Constant Summary collapse

VERSION =
"2.0.0"

Class Method Summary collapse

Class Method Details

.configObject



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

def config
  @config ||= Config.new
end

.configure {|config| ... } ⇒ Object

Yields:



24
25
26
# File 'lib/downstream.rb', line 24

def configure
  yield config
end

.publish(event) ⇒ Object



54
55
56
# File 'lib/downstream.rb', line 54

def publish(event)
  pubsub.publish("#{config.namespace}.#{event.type}", event)
end

.subscribe(subscriber = nil, to: nil, async: false, &block) ⇒ Object

Raises:

  • (ArgumentError)


28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/downstream.rb', line 28

def subscribe(subscriber = nil, to: nil, async: false, &block)
  subscriber ||= block if block
  raise ArgumentError, "Subsriber must be present" if subscriber.nil?

  construct_identifiers(subscriber, to).map do
    pubsub.subscribe(_1, subscriber, async: async)
  end.then do
    next _1.first if _1.size == 1

    _1
  end
end

.subscribed(subscriber, to: nil, &block) ⇒ Object

temporary subscriptions

Raises:

  • (ArgumentError)


42
43
44
45
46
47
48
49
50
51
52
# File 'lib/downstream.rb', line 42

def subscribed(subscriber, to: nil, &block)
  raise ArgumentError, "Subsriber must be present" if subscriber.nil?

  construct_identifiers(subscriber, to).map do
    pubsub.subscribed(_1, subscriber, &block)
  end.then do
    next _1.first if _1.size == 1

    _1
  end
end