active_event_store 1.0.1 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +11 -0
- data/README.md +3 -1
- data/lib/active_event_store/rspec/have_enqueued_async_subscriber_for.rb +1 -1
- data/lib/active_event_store/rspec/have_published_event.rb +1 -1
- data/lib/active_event_store/subscriber_job.rb +10 -6
- data/lib/active_event_store/version.rb +1 -1
- data/lib/active_event_store.rb +1 -1
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 40a03429293a097e9e128b80c543c1a8a6e605caf9c400d93b83753af4ff95d5
|
4
|
+
data.tar.gz: c4576de3f33de50480e634e9fe8aa16ccb23a7acb23453e54f9ba23310dbc763
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3c80d23fe4f5f6be97c847f2b4cfd7e388793121b632e5edc7b24241f8fd36fc1078d1b15b2ca744e80d1ae75afae65ec1c925c87a35c9ec95da6c6dff671c2c
|
7
|
+
data.tar.gz: 565fcba5bb1469be55feac9501d539ea6450f6682cb2a2773116e811cb1127c605ed9f393ea98055f8e30294758a1a3f30ce4b419eaec2e9727b8232364a4c01
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,16 @@
|
|
2
2
|
|
3
3
|
## master
|
4
4
|
|
5
|
+
## 1.1.0 (2023-08-24)
|
6
|
+
|
7
|
+
- Require Ruby 2.7+. ([@palkan][])
|
8
|
+
|
9
|
+
- Fix compatibility with RES 2.11 ([@palkan][])
|
10
|
+
|
11
|
+
## 1.0.2 (2021-03-15)
|
12
|
+
|
13
|
+
- Support using classes with `#call` as async subscribers. ([@caws][])
|
14
|
+
|
5
15
|
## 1.0.1 (2021-09-16)
|
6
16
|
|
7
17
|
- Add minitest assertions: `assert_event_published`, `refute_event_published`, `assert_async_event_subscriber_enqueued` ([@chriscz][])
|
@@ -26,3 +36,4 @@ Now `ActiveSupport.on_load(:active_event_store) { ... }` works.
|
|
26
36
|
|
27
37
|
[@palkan]: https://github.com/palkan
|
28
38
|
[@chriscz]: https://github.com/chriscz
|
39
|
+
[@caws]: https://github.com/caws
|
data/README.md
CHANGED
@@ -140,12 +140,14 @@ ActiveSupport.on_load :active_event_store do |store|
|
|
140
140
|
end
|
141
141
|
```
|
142
142
|
|
143
|
-
Subscribers could be any callable Ruby objects that accept a single argument (event) as its input.
|
143
|
+
Subscribers could be any callable Ruby objects that accept a single argument (event) as its input or classes that inherit from `Class` and have `#call` as an instance method.
|
144
144
|
|
145
145
|
We suggest putting subscribers to the `app/subscribers` folder using the following convention: `app/subscribers/on_<event_type>/<subscriber.rb>`, e.g. `app/subscribers/on_profile_created/create_chat_user.rb`.
|
146
146
|
|
147
147
|
**NOTE:** Active Job must be loaded to use async subscribers (i.e., `require "active_job/railtie"` or `require "rails/all"` in your `config/application.rb`).
|
148
148
|
|
149
|
+
**NOTE:** Subscribers that inherit from `Class` and implement `call` as a class method will not be instantiated.
|
150
|
+
|
149
151
|
### Testing
|
150
152
|
|
151
153
|
You can test subscribers as normal Ruby objects.
|
@@ -116,7 +116,7 @@ module ActiveEventStore
|
|
116
116
|
end
|
117
117
|
|
118
118
|
def message_expectation_modifier
|
119
|
-
number_modifier = @expected_number == 1 ? "once" : "#{@expected_number} times"
|
119
|
+
number_modifier = (@expected_number == 1) ? "once" : "#{@expected_number} times"
|
120
120
|
case @expectation_type
|
121
121
|
when :exactly then "exactly #{number_modifier}"
|
122
122
|
when :at_most then "at most #{number_modifier}"
|
@@ -14,11 +14,11 @@ module ActiveEventStore
|
|
14
14
|
|
15
15
|
raise ArgumentError, "Async subscriber must be a module/class, not instance" unless callable.is_a?(Module)
|
16
16
|
|
17
|
-
if callable.const_defined?(
|
18
|
-
callable.const_get(
|
17
|
+
if callable.const_defined?(:SubscriberJob, false)
|
18
|
+
callable.const_get(:SubscriberJob, false)
|
19
19
|
else
|
20
20
|
callable.const_set(
|
21
|
-
|
21
|
+
:SubscriberJob,
|
22
22
|
Class.new(self).tap do |job|
|
23
23
|
queue_as ActiveEventStore.config.job_queue_name
|
24
24
|
|
@@ -31,14 +31,14 @@ module ActiveEventStore
|
|
31
31
|
def for(callable)
|
32
32
|
raise ArgumentError, "Async subscriber must be a module/class" unless callable.is_a?(Module)
|
33
33
|
|
34
|
-
callable.const_defined?(
|
35
|
-
callable.const_get(
|
34
|
+
callable.const_defined?(:SubscriberJob, false) ?
|
35
|
+
callable.const_get(:SubscriberJob, false) :
|
36
36
|
nil
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
40
40
|
def perform(payload)
|
41
|
-
event = event_store.deserialize(**payload, serializer: ActiveEventStore.config.serializer)
|
41
|
+
event = event_store.deserialize(**payload.symbolize_keys, serializer: ActiveEventStore.config.serializer)
|
42
42
|
|
43
43
|
event_store.with_metadata(**event.metadata.to_h) do
|
44
44
|
subscriber.call(event)
|
@@ -48,6 +48,10 @@ module ActiveEventStore
|
|
48
48
|
private
|
49
49
|
|
50
50
|
def subscriber
|
51
|
+
if self.class.subscriber.is_a?(Class) && !self.class.subscriber.respond_to?(:call)
|
52
|
+
return self.class.subscriber.new
|
53
|
+
end
|
54
|
+
|
51
55
|
self.class.subscriber
|
52
56
|
end
|
53
57
|
|
data/lib/active_event_store.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_event_store
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vladimir Dementyev
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-08-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails_event_store
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 2.
|
19
|
+
version: 2.11.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 2.
|
26
|
+
version: 2.11.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -135,14 +135,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
135
135
|
requirements:
|
136
136
|
- - ">="
|
137
137
|
- !ruby/object:Gem::Version
|
138
|
-
version: '2.
|
138
|
+
version: '2.7'
|
139
139
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
140
140
|
requirements:
|
141
141
|
- - ">="
|
142
142
|
- !ruby/object:Gem::Version
|
143
143
|
version: '0'
|
144
144
|
requirements: []
|
145
|
-
rubygems_version: 3.
|
145
|
+
rubygems_version: 3.4.8
|
146
146
|
signing_key:
|
147
147
|
specification_version: 4
|
148
148
|
summary: Rails Event Store in a more Rails way
|