Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Subscriptions redesigned #665

Closed
wants to merge 23 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
be31df8
Redefine subscriptions - breaking changes
mpraglowski Aug 9, 2019
39bc7ad
Refactor subscriptions
mpraglowski Aug 9, 2019
8ff0e36
Subscription storage is optional
mpraglowski Aug 9, 2019
972be0a
All dispatchers & schedulers receive now subscription object instead …
mpraglowski Aug 10, 2019
b693e49
Single subscriptions store is enough
mpraglowski Aug 16, 2019
33f34cb
Subscription global or assigned to specific type - it's just an imple…
mpraglowski Aug 16, 2019
2c9e3aa
Minor improvement & fixes
mpraglowski Aug 16, 2019
554cdbe
Docs & lint/specs for subscriptions store
mpraglowski Aug 16, 2019
4f76f27
Docs & specs for Subscription object
mpraglowski Aug 16, 2019
e18ceb3
No more local & global subscriptions, there are main subscription sto…
mpraglowski Aug 16, 2019
c8dedab
Do not need that anymore
mpraglowski Aug 16, 2019
29e62b4
Simplify subscriptions store API
mpraglowski Aug 16, 2019
acc8184
Must be excluded from mutation tests as test where it could be trigge…
mpraglowski Aug 16, 2019
2bd6c6d
Kill mutant
mpraglowski Aug 16, 2019
9aefcdf
Typo fix
mpraglowski Aug 16, 2019
636cafb
It does not make sense to require subscription store to be chainable
mpraglowski Aug 16, 2019
ff945e7
Fix subscriptions store lint namespace
mpraglowski Aug 16, 2019
cec639c
Add instrumented subscriptions store
mpraglowski Aug 16, 2019
b82767b
Use store factory for thread store instead of just a class
mpraglowski Aug 16, 2019
570590f
Again, keep Ruby 2.4 compatibility for now
mpraglowski Sep 6, 2019
7140093
Kill mutations
mpraglowski Sep 6, 2019
25dd989
Add frozen_string_literal: true in all changed files
mpraglowski Sep 6, 2019
4ba25e3
Document subscriptions provider class
mpraglowski Sep 6, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions ruby_event_store/lib/ruby_event_store/global_subscription.rb
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
module RubyEventStore
class GlobalSubscription
def initialize(subscriber, store)
def initialize(subscriber, store: nil)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't yet see the purpose, checking next commits.

@subscriber = subscriber
@store = store
@store.add(self)
@store.add(self) if @store
end

def call(event)
(Class === subscriber ? subscriber.new : subscriber).call(event)
end

def unsubscribe
@store.delete(self)
@store.delete(self) if @store
end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

with #call aliased to #unsubscribe this would not be a breaking change, but #call is already taken...


def inspect
Expand Down
8 changes: 4 additions & 4 deletions ruby_event_store/lib/ruby_event_store/subscription.rb
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
module RubyEventStore
class Subscription
def initialize(subscriber, event_types, store)
def initialize(subscriber, event_types, store: nil)
@subscriber = subscriber
@store = store
@event_types = event_types
event_types.each{ |type| @store.add(type, self) }
@store = store
event_types.each{ |type| @store.add(type, self) } if @store
end

def call(event)
(Class === subscriber ? subscriber.new : subscriber).call(event)
end

def unsubscribe
event_types.each{ |type| @store.delete(type, self) }
event_types.each{ |type| @store.delete(type, self) } if @store
end

def inspect
Expand Down
4 changes: 2 additions & 2 deletions ruby_event_store/lib/ruby_event_store/subscriptions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def initialize(store)
end

def add(subscription, event_types)
Subscription.new(subscription, event_types, @store.value)
Subscription.new(subscription, event_types, store: @store.value)
end

def all_for(event_type)
Expand All @@ -117,7 +117,7 @@ def initialize(store)
end

def add(subscription)
GlobalSubscription.new(subscription, @store.value)
GlobalSubscription.new(subscription, store: @store.value)
end

def all_for(_event_type)
Expand Down
8 changes: 2 additions & 6 deletions ruby_event_store/spec/dispatcher_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,14 @@ def call

specify "calls subscribed instance" do
expect(handler).to receive(:call).with(event)
store = double(:store)
allow(store).to receive(:add)
subscription = GlobalSubscription.new(handler, store)
subscription = GlobalSubscription.new(handler)
Dispatcher.new.call(subscription, event, serialized_event)
end

specify "calls subscribed class" do
expect(HandlerClass).to receive(:new).and_return(handler)
expect(handler).to receive(:call).with(event)
store = double(:store)
allow(store).to receive(:add)
subscription = GlobalSubscription.new(HandlerClass, store)
subscription = GlobalSubscription.new(HandlerClass)
Dispatcher.new.call(subscription, event, serialized_event)
end

Expand Down