Module: ActiveEventStore

Defined in:
lib/active_event_store/version.rb,
lib/active_event_store.rb,
lib/active_event_store/event.rb,
lib/active_event_store/config.rb,
lib/active_event_store/engine.rb,
lib/active_event_store/mapper.rb,
lib/active_event_store/mapping.rb,
lib/active_event_store/test_helper.rb,
lib/active_event_store/subscriber_job.rb,
lib/active_event_store/rspec/have_published_event.rb,
lib/active_event_store/test_helper/event_published_matcher.rb,
lib/active_event_store/rspec/have_enqueued_async_subscriber_for.rb

Overview

:nodoc:

Defined Under Namespace

Modules: TestHelper Classes: Config, Engine, Event, HaveEnqueuedAsyncSubscriberFor, HavePublishedEvent, Mapper, Mapping, SubscriberJob

Constant Summary collapse

VERSION =
"1.0.2"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.event_storeObject

Underlying RailsEventStore



17
18
19
# File 'lib/active_event_store.rb', line 17

def event_store
  @event_store
end

Class Method Details

.configObject



23
24
25
# File 'lib/active_event_store.rb', line 23

def config
  @config ||= Config.new
end

.mappingObject



19
20
21
# File 'lib/active_event_store.rb', line 19

def mapping
  @mapping ||= Mapping.new
end

.publish(event, **options) ⇒ Object



52
53
54
# File 'lib/active_event_store.rb', line 52

def publish(event, **options)
  event_store.publish event, **options
end

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



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/active_event_store.rb', line 27

def subscribe(subscriber = nil, to: nil, sync: false, &block)
  subscriber ||= block

  to ||= infer_event_from_subscriber(subscriber) if subscriber.is_a?(Module)

  if to.nil?
    raise ArgumentError, "Couldn't infer event from subscriber. " \
                          "Please, specify event using `to:` option"
  end

  identifier =
    if to.is_a?(Class) && ActiveEventStore::Event >= to
      # register event
      mapping.register_event to

      to.identifier
    else
      to
    end

  subscriber = SubscriberJob.from(subscriber) unless sync

  event_store.subscribe subscriber, to: [identifier]
end