Skip to content

Commit ce2e5cf

Browse files
committed
Prefer lazy event store initialization
ref: eb73818
1 parent 0f8aef1 commit ce2e5cf

File tree

2 files changed

+5
-8
lines changed

2 files changed

+5
-8
lines changed

rails_event_store/lib/rails_event_store/async_handler_helpers.rb

Lines changed: 3 additions & 5 deletions
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

rails_event_store/spec/async_handler_helpers_spec.rb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,15 +95,14 @@ def perform(event)
9595
end
9696

9797
specify "with specified event store" do
98-
HandlerWithAnotherEventStore.prepend RailsEventStore::AsyncHandler.with(event_store: another_event_store)
98+
HandlerWithAnotherEventStore.prepend RailsEventStore::AsyncHandler.with(event_store_locator: -> { another_event_store} )
9999
event_store.subscribe_to_all_events(HandlerWithAnotherEventStore)
100100
event_store.publish(ev = RubyEventStore::Event.new)
101101
expect($queue.pop).to eq(ev)
102102
end
103103

104104
specify "with specified event store locator" do
105105
HandlerWithEventStoreLocator.prepend RailsEventStore::AsyncHandler.with(
106-
event_store: nil,
107106
event_store_locator: -> { another_event_store }
108107
)
109108
another_event_store.subscribe_to_all_events(HandlerWithEventStoreLocator)
@@ -113,7 +112,7 @@ def perform(event)
113112

114113
specify "with specified serializer" do
115114
HandlerWithSpecifiedSerializer.prepend RailsEventStore::AsyncHandler.with(
116-
event_store: json_event_store,
115+
event_store_locator: -> { json_event_store },
117116
serializer: JSON
118117
)
119118
json_event_store.subscribe_to_all_events(HandlerWithSpecifiedSerializer)

0 commit comments

Comments
 (0)