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/domain_event.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
Defined Under Namespace
Modules: TestHelper
Classes: Config, DomainEvent, Engine, Event, HaveEnqueuedAsyncSubscriberFor, HavePublishedEvent, Mapper, Mapping, SubscriberJob
Constant Summary
collapse
- VERSION =
"1.4.0"
Class Attribute Summary collapse
Class Method Summary
collapse
Class Attribute Details
.event_store ⇒ Object
Underlying RailsEventStore
18
19
20
|
# File 'lib/active_event_store.rb', line 18
def event_store
@event_store
end
|
Class Method Details
.config ⇒ Object
24
25
26
|
# File 'lib/active_event_store.rb', line 24
def config
@config ||= Config.new
end
|
.mapping ⇒ Object
20
21
22
|
# File 'lib/active_event_store.rb', line 20
def mapping
@mapping ||= Mapping.new
end
|
.publish(event, **options) ⇒ Object
63
64
65
|
# File 'lib/active_event_store.rb', line 63
def publish(event, **options)
event_store.publish event, **options
end
|
.subscribe(subscriber = nil, to: nil, sync: false, wait: nil, wait_until: nil, &block) ⇒ Object
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
# File 'lib/active_event_store.rb', line 28
def subscribe(subscriber = nil, to: nil, sync: false, wait: nil, wait_until: nil, &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
assert_valid_enqueue_options!(sync: sync, wait: wait, wait_until: wait_until)
identifier =
if to.is_a?(Class) && to <= ActiveEventStore::Event
mapping.register_event to
to.identifier
else
to
end
unless sync
subscriber = SubscriberJob.from(subscriber)
enqueue_options = {wait: wait, wait_until: wait_until}.compact
subscriber = subscriber.set(**enqueue_options) unless enqueue_options.empty?
end
event_store.subscribe subscriber, to: [identifier]
end
|