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/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/pubsub_adapters/stateless/subscriber_job.rb

Defined Under Namespace

Modules: Stateless Classes: AbstractPubsub, Config, Engine, Event, HavePublishedEvent

Constant Summary collapse

VERSION =
"1.2.0"

Class Method Summary collapse

Class Method Details

.configObject



18
19
20
# File 'lib/downstream.rb', line 18

def config
  @config ||= Config.new
end

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

Yields:



22
23
24
# File 'lib/downstream.rb', line 22

def configure
  yield config
end

.publish(event) ⇒ Object



44
45
46
# File 'lib/downstream.rb', line 44

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

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

Raises:

  • (ArgumentError)


26
27
28
29
30
31
32
33
# File 'lib/downstream.rb', line 26

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

  identifier = construct_identifier(subscriber, to)

  pubsub.subscribe(identifier, subscriber, async: async)
end

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

temporary subscriptions

Raises:

  • (ArgumentError)


36
37
38
39
40
41
42
# File 'lib/downstream.rb', line 36

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

  identifier = construct_identifier(subscriber, to)

  pubsub.subscribed(identifier, subscriber, &block)
end