omnes 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/CHANGELOG.md +12 -1
- data/README.md +22 -6
- data/lib/omnes/bus.rb +12 -0
- data/lib/omnes/subscriber/state.rb +21 -10
- data/lib/omnes/version.rb +1 -1
- metadata +2 -3
- data/Gemfile.lock +0 -86
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: eb5f0bfcfdcbaffdfe41c807db505023e8bb84cacdb56378a0851b9effdd51c1
|
4
|
+
data.tar.gz: 4b2bb740f6525c96651912a88f7738b04ceeca699a4af7b3f883f68a3e60eb55
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 55b5fe1e1bc4fd5cd10e6683ff7539be5dec727f4399758d7fcfe3fd3d485d30fe4d99e8c2f1354bf1aef28f3efffd991573a89d827edf3839827c6fcfcd71d8
|
7
|
+
data.tar.gz: cc1c6c69c4e98442abad019ffac4dfa56221924182fd041d9830d7c72660eec09b4173c812e90969fb49f28cd7968acaeb91ab89c94bb8a9efb96e3bbe5626e7
|
data/.gitignore
CHANGED
data/CHANGELOG.md
CHANGED
@@ -4,6 +4,16 @@ All notable changes to this project will be documented in this file.
|
|
4
4
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
5
5
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
6
6
|
|
7
|
+
## Unreleased
|
8
|
+
|
9
|
+
## [0.2.1] - 2022-04-19
|
10
|
+
|
11
|
+
### Added
|
12
|
+
- Added `Omnes::Bus#clear` for autoloading [#4](https://github.com/nebulab/omnes/pull/4).
|
13
|
+
|
14
|
+
### Changed
|
15
|
+
- Fix re-adding autodiscovered subscriptions on subsequent calls [#5](https://github.com/nebulab/omnes/pull/5).
|
16
|
+
|
7
17
|
## [0.2.0] - 2022-04-15
|
8
18
|
|
9
19
|
### Added
|
@@ -13,6 +23,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
13
23
|
|
14
24
|
## [0.1.0] - 2022-03-23
|
15
25
|
|
16
|
-
[Unreleased]: https://github.com/nebulab/omnes/compare/v0.2.
|
26
|
+
[Unreleased]: https://github.com/nebulab/omnes/compare/v0.2.1...HEAD
|
27
|
+
[0.2.1]: https://github.com/nebulab/omnes/compare/v0.2.0...v0.2.1
|
17
28
|
[0.2.0]: https://github.com/nebulab/omnes/compare/v0.1.0...v0.2.0
|
18
29
|
[0.1.0]: https://github.com/nebulab/omnes/releases/tag/v0.1.0
|
data/README.md
CHANGED
@@ -476,18 +476,29 @@ handle :order_created, with: ThreadAdapter.new(:order_created)
|
|
476
476
|
# ...
|
477
477
|
```
|
478
478
|
|
479
|
-
##
|
480
|
-
|
481
|
-
### Unsubscribing
|
479
|
+
## Unsubscribing & clearing
|
482
480
|
|
483
481
|
You can unsubscribe a given subscription by passing its
|
484
|
-
[reference](#referencing-subscriptions) to `Omnes::Bus#unsubscribe
|
482
|
+
[reference](#referencing-subscriptions) to `Omnes::Bus#unsubscribe` (see how to
|
483
|
+
[reference subscriptions](#referencing-subscriptions)):
|
485
484
|
|
486
485
|
```ruby
|
487
486
|
subscription = bus.subscribe(:order_created, OrderCreationEmailSubscription.new)
|
488
487
|
bus.unsubscribe(subscription)
|
489
488
|
```
|
490
489
|
|
490
|
+
Sometimes you might need to leave your bus in a pristine state, with no events
|
491
|
+
registered or active subscriptions. That can be useful for autoloading in
|
492
|
+
development:
|
493
|
+
|
494
|
+
```ruby
|
495
|
+
bus.clear
|
496
|
+
bus.registry.event_names # => []
|
497
|
+
bus.subscriptions # => []
|
498
|
+
```
|
499
|
+
|
500
|
+
## Debugging
|
501
|
+
|
491
502
|
### Registration
|
492
503
|
|
493
504
|
Whenever you register an event, you get back an [`Omnes::Registry::Registration`](lib/omnes/registry.rb)
|
@@ -629,9 +640,14 @@ require "omnes"
|
|
629
640
|
Omnes.config.subscriber.autodiscover = true
|
630
641
|
|
631
642
|
Bus = Omnes::Bus.new
|
632
|
-
Bus.register(:order_created)
|
633
643
|
|
634
|
-
|
644
|
+
Rails.application.config.to_prepare do
|
645
|
+
Bus.clear
|
646
|
+
|
647
|
+
Bus.register(:order_created)
|
648
|
+
|
649
|
+
OrderCreationEmailSubscriber.new.subscribe_to(Bus)
|
650
|
+
end
|
635
651
|
```
|
636
652
|
|
637
653
|
We can define `OrderCreationEmailSubscriber` in
|
data/lib/omnes/bus.rb
CHANGED
@@ -287,6 +287,18 @@ module Omnes
|
|
287
287
|
subscriptions.find { |subscription| subscription.id == id }
|
288
288
|
end
|
289
289
|
|
290
|
+
# Clears all registered events and subscriptions
|
291
|
+
#
|
292
|
+
# Useful for code reloading.
|
293
|
+
#
|
294
|
+
# @return [Omnes::Bus]
|
295
|
+
def clear
|
296
|
+
tap do
|
297
|
+
@subscriptions = []
|
298
|
+
@registry = Registry.new
|
299
|
+
end
|
300
|
+
end
|
301
|
+
|
290
302
|
private
|
291
303
|
|
292
304
|
def execute_subscriptions_for_event(event, publication_context)
|
@@ -24,9 +24,9 @@ module Omnes
|
|
24
24
|
def call(bus, instance)
|
25
25
|
raise MultipleSubscriberSubscriptionAttemptError if already_called?(bus, instance)
|
26
26
|
|
27
|
-
|
27
|
+
all_subscription_definitions = subscription_definitions + autodiscovered_subscription_definitions(bus, instance)
|
28
28
|
|
29
|
-
definitions =
|
29
|
+
definitions = all_subscription_definitions.map { |defn| defn.(bus, instance) }
|
30
30
|
|
31
31
|
subscribe_definitions(definitions, bus, instance).tap do
|
32
32
|
mark_as_called(bus, instance)
|
@@ -47,21 +47,32 @@ module Omnes
|
|
47
47
|
@calling_cache << [bus, instance]
|
48
48
|
end
|
49
49
|
|
50
|
-
def
|
51
|
-
|
52
|
-
method_name = autodiscover_strategy.(event_name)
|
53
|
-
next unless instance.respond_to?(method_name, true)
|
50
|
+
def autodiscovered_subscription_definitions(bus, instance)
|
51
|
+
return [] unless autodiscover_strategy
|
54
52
|
|
55
|
-
|
53
|
+
bus.registry.event_names.reduce([]) do |defs, event_name|
|
54
|
+
method_name = autodiscover_strategy.(event_name)
|
55
|
+
if instance.respond_to?(method_name, true)
|
56
56
|
[
|
57
|
-
|
58
|
-
|
59
|
-
Subscription.random_id
|
57
|
+
*defs,
|
58
|
+
autodiscovered_subscription_definition(event_name, method_name)
|
60
59
|
]
|
60
|
+
else
|
61
|
+
defs
|
61
62
|
end
|
62
63
|
end
|
63
64
|
end
|
64
65
|
|
66
|
+
def autodiscovered_subscription_definition(event_name, method_name)
|
67
|
+
lambda do |_bus, _instance|
|
68
|
+
[
|
69
|
+
Subscription::SINGLE_EVENT_MATCHER.curry[event_name],
|
70
|
+
Adapter.Type(Adapter::Method.new(method_name)),
|
71
|
+
Subscription.random_id
|
72
|
+
]
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
65
76
|
def subscribe_definitions(definitions, bus, instance)
|
66
77
|
matcher_with_callbacks = definitions.map do |(matcher, adapter, id)|
|
67
78
|
[matcher, adapter.curry[instance], id]
|
data/lib/omnes/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: omnes
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marc Busqué
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-04-
|
11
|
+
date: 2022-04-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activejob
|
@@ -87,7 +87,6 @@ files:
|
|
87
87
|
- CHANGELOG.md
|
88
88
|
- CODE_OF_CONDUCT.md
|
89
89
|
- Gemfile
|
90
|
-
- Gemfile.lock
|
91
90
|
- LICENSE.txt
|
92
91
|
- README.md
|
93
92
|
- Rakefile
|
data/Gemfile.lock
DELETED
@@ -1,86 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
omnes (0.1.0)
|
5
|
-
|
6
|
-
GEM
|
7
|
-
remote: https://rubygems.org/
|
8
|
-
specs:
|
9
|
-
activejob (7.0.2.3)
|
10
|
-
activesupport (= 7.0.2.3)
|
11
|
-
globalid (>= 0.3.6)
|
12
|
-
activesupport (7.0.2.3)
|
13
|
-
concurrent-ruby (~> 1.0, >= 1.0.2)
|
14
|
-
i18n (>= 1.6, < 2)
|
15
|
-
minitest (>= 5.1)
|
16
|
-
tzinfo (~> 2.0)
|
17
|
-
ast (2.4.2)
|
18
|
-
concurrent-ruby (1.1.9)
|
19
|
-
connection_pool (2.2.5)
|
20
|
-
diff-lcs (1.5.0)
|
21
|
-
globalid (1.0.0)
|
22
|
-
activesupport (>= 5.0)
|
23
|
-
i18n (1.10.0)
|
24
|
-
concurrent-ruby (~> 1.0)
|
25
|
-
minitest (5.15.0)
|
26
|
-
parallel (1.21.0)
|
27
|
-
parser (3.1.1.0)
|
28
|
-
ast (~> 2.4.1)
|
29
|
-
rack (2.2.3)
|
30
|
-
rainbow (3.1.1)
|
31
|
-
rake (12.3.3)
|
32
|
-
redcarpet (3.5.1)
|
33
|
-
redis (4.6.0)
|
34
|
-
regexp_parser (2.2.1)
|
35
|
-
rexml (3.2.5)
|
36
|
-
rspec (3.11.0)
|
37
|
-
rspec-core (~> 3.11.0)
|
38
|
-
rspec-expectations (~> 3.11.0)
|
39
|
-
rspec-mocks (~> 3.11.0)
|
40
|
-
rspec-core (3.11.0)
|
41
|
-
rspec-support (~> 3.11.0)
|
42
|
-
rspec-expectations (3.11.0)
|
43
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
44
|
-
rspec-support (~> 3.11.0)
|
45
|
-
rspec-mocks (3.11.0)
|
46
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
47
|
-
rspec-support (~> 3.11.0)
|
48
|
-
rspec-support (3.11.0)
|
49
|
-
rubocop (1.25.1)
|
50
|
-
parallel (~> 1.10)
|
51
|
-
parser (>= 3.1.0.0)
|
52
|
-
rainbow (>= 2.2.2, < 4.0)
|
53
|
-
regexp_parser (>= 1.8, < 3.0)
|
54
|
-
rexml
|
55
|
-
rubocop-ast (>= 1.15.1, < 2.0)
|
56
|
-
ruby-progressbar (~> 1.7)
|
57
|
-
unicode-display_width (>= 1.4.0, < 3.0)
|
58
|
-
rubocop-ast (1.16.0)
|
59
|
-
parser (>= 3.1.1.0)
|
60
|
-
ruby-progressbar (1.11.0)
|
61
|
-
sidekiq (6.4.1)
|
62
|
-
connection_pool (>= 2.2.2)
|
63
|
-
rack (~> 2.0)
|
64
|
-
redis (>= 4.2.0)
|
65
|
-
tzinfo (2.0.4)
|
66
|
-
concurrent-ruby (~> 1.0)
|
67
|
-
unicode-display_width (2.1.0)
|
68
|
-
webrick (1.7.0)
|
69
|
-
yard (0.9.27)
|
70
|
-
webrick (~> 1.7.0)
|
71
|
-
|
72
|
-
PLATFORMS
|
73
|
-
x86_64-linux
|
74
|
-
|
75
|
-
DEPENDENCIES
|
76
|
-
activejob (~> 7.0)
|
77
|
-
omnes!
|
78
|
-
rake (~> 12.0)
|
79
|
-
redcarpet (~> 3.5)
|
80
|
-
rspec (~> 3.0)
|
81
|
-
rubocop (~> 1.25)
|
82
|
-
sidekiq (~> 6.4)
|
83
|
-
yard (~> 0.9)
|
84
|
-
|
85
|
-
BUNDLED WITH
|
86
|
-
2.2.3
|