Skip to content

Commit 72a8e99

Browse files
committed
Prefer lazy event store initialization
ref: eb73818
1 parent cab0cff commit 72a8e99

File tree

2 files changed

+5
-8
lines changed

2 files changed

+5
-8
lines changed

Diff for: rails_event_store/lib/rails_event_store/async_handler_helpers.rb

+3-5
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,12 @@ def self.with_defaults
77
end
88

99
def self.with(
10-
event_store: Rails.configuration.event_store,
11-
event_store_locator: nil,
12-
serializer: RubyEventStore::Serializers::YAML
10+
serializer: RubyEventStore::Serializers::YAML,
11+
event_store_locator: -> { Rails.configuration.event_store }
1312
)
1413
Module.new do
1514
define_method :perform do |payload|
16-
event_store = event_store_locator.call if event_store_locator
17-
super(event_store.deserialize(serializer: serializer, **payload.transform_keys(&:to_sym)))
15+
super(event_store_locator.call.deserialize(serializer: serializer, **payload.transform_keys(&:to_sym)))
1816
end
1917
end
2018
end

Diff for: rails_event_store/spec/async_handler_helpers_spec.rb

+2-3
Original file line numberDiff line numberDiff line change
@@ -83,15 +83,14 @@ def perform(_event)
8383
end
8484

8585
specify "with specified event store" do
86-
HandlerWithAnotherEventStore.prepend RailsEventStore::AsyncHandler.with(event_store: another_event_store)
86+
HandlerWithAnotherEventStore.prepend RailsEventStore::AsyncHandler.with(event_store_locator: -> { another_event_store} )
8787
event_store.subscribe_to_all_events(HandlerWithAnotherEventStore)
8888
event_store.publish(ev = RubyEventStore::Event.new)
8989
expect($queue.pop).to eq(ev)
9090
end
9191

9292
specify "with specified event store locator" do
9393
HandlerWithEventStoreLocator.prepend RailsEventStore::AsyncHandler.with(
94-
event_store: nil,
9594
event_store_locator: -> { another_event_store }
9695
)
9796
another_event_store.subscribe_to_all_events(HandlerWithEventStoreLocator)
@@ -101,7 +100,7 @@ def perform(_event)
101100

102101
specify "with specified serializer" do
103102
HandlerWithSpecifiedSerializer.prepend RailsEventStore::AsyncHandler.with(
104-
event_store: json_event_store,
103+
event_store_locator: -> { json_event_store },
105104
serializer: JSON
106105
)
107106
json_event_store.subscribe_to_all_events(HandlerWithSpecifiedSerializer)

0 commit comments

Comments
 (0)