active_event_store 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e19560b568e8765b86d3925070dd1414b0de0545107e1dc1c7df4e3402148690
4
- data.tar.gz: 87816ce897dc26614f8834993373bb271345c25934142f055547ad0f5023fe22
3
+ metadata.gz: f4ccb82314fce7aa4504e6834af793ad82e4613ef970a0277664de839e72a543
4
+ data.tar.gz: 38ea7210977f150226cf63f3cdec4793210e054e207cf71bcfcf5643cab21b28
5
5
  SHA512:
6
- metadata.gz: acf6017590c69d26066617c86ab63cd658c2307e8da89c53ec0afe18ebb4b384430bde9f632806f4e92a26293ed37cffa1c7abaa55ca2cd5f312d70d98ba873a
7
- data.tar.gz: 181e900564fb3640a5484045ebbe6170b3871e05ea10a8e443bcadf7a530bf58bc227f4101d998a92ff96b82b569d1d24adcc1f97d3195c57fa2f0023c7db7db
6
+ metadata.gz: 26ff53ad69fe94b9643031511072ef1d3b89e17eebae6b492570ad56829afc03ccb39c1ae16b26e3da038a549e4ae63c95eab117e1f4f0781e1202b32d6662b1
7
+ data.tar.gz: bb66fa72aed216e1328dc7b52737a273de13da41dcdc723c6250e015c7aee5574523c9ed6de876ae0525599076326f6bb847c5115eb146801f8e177dc04b13b4
data/CHANGELOG.md CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  ## master
4
4
 
5
+ ## 1.0.2 (2021-03-15)
6
+
7
+ - Support using classes with `#call` as async subscribers. ([@caws][])
8
+
5
9
  ## 1.0.1 (2021-09-16)
6
10
 
7
11
  - Add minitest assertions: `assert_event_published`, `refute_event_published`, `assert_async_event_subscriber_enqueued` ([@chriscz][])
@@ -26,3 +30,4 @@ Now `ActiveSupport.on_load(:active_event_store) { ... }` works.
26
30
 
27
31
  [@palkan]: https://github.com/palkan
28
32
  [@chriscz]: https://github.com/chriscz
33
+ [@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.
@@ -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?("SubscriberJob", false)
18
- callable.const_get("SubscriberJob", false)
17
+ if callable.const_defined?(:SubscriberJob, false)
18
+ callable.const_get(:SubscriberJob, false)
19
19
  else
20
20
  callable.const_set(
21
- "SubscriberJob",
21
+ :SubscriberJob,
22
22
  Class.new(self).tap do |job|
23
23
  queue_as ActiveEventStore.config.job_queue_name
24
24
 
@@ -31,8 +31,8 @@ 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?("SubscriberJob", false) ?
35
- callable.const_get("SubscriberJob", false) :
34
+ callable.const_defined?(:SubscriberJob, false) ?
35
+ callable.const_get(:SubscriberJob, false) :
36
36
  nil
37
37
  end
38
38
  end
@@ -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
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ActiveEventStore # :nodoc:
4
- VERSION = "1.0.1"
4
+ VERSION = "1.0.2"
5
5
  end
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.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vladimir Dementyev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-09-16 00:00:00.000000000 Z
11
+ date: 2022-03-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails_event_store
@@ -142,7 +142,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
142
142
  - !ruby/object:Gem::Version
143
143
  version: '0'
144
144
  requirements: []
145
- rubygems_version: 3.2.15
145
+ rubygems_version: 3.2.22
146
146
  signing_key:
147
147
  specification_version: 4
148
148
  summary: Rails Event Store in a more Rails way