event_engine-subscribers 0.3.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 77ec2b6b5c9768d1968ead2a2d567e796a91747036be8d6c407137a36997c781
4
- data.tar.gz: 4f97fd5b867ca07942c082c3e37a65e4a0bb452c6e7c4d59fd409561ccb9ea23
3
+ metadata.gz: 9911cefcbfa87b20178f615e68e88cef8f57da763ad42fcdf10a3f7f1b9d7be9
4
+ data.tar.gz: 1aa83bfbbea17ba4b3d2555f08509545f487e94d38abc52409de1a97bfa52109
5
5
  SHA512:
6
- metadata.gz: b806c0dbe05a8c57a1d3b1c0cd0fbe7937d015f5822d37c3f5feafd083d922a5f528b871564aaa8259866d8f0bd6ca4b90af63351788b8521f4baadf57346201
7
- data.tar.gz: fcc63467dcf27dc0021304dd36821de214c30f9eff44efca1f3f2cd6a9b5a59cbe6f43693547f28e86bc4b0f7dfa949f8d912ee25c914bd1ff35328ba9aed617
6
+ metadata.gz: 64e5c8652616821523641c4ffa5e17afb165e052847cde405c42f9ba2e852ed90a5c77add76ba3d6315e4fe230b97c280ff6213db5671c18a94e41757d957f82
7
+ data.tar.gz: 6b420c78274b70abf4cda7d544074e692e400409dac035937204b2270a0a2605b9a3f63198d46b0c9201c49cd3406aab5a6d1f789de28defe4c69aaf4f6fd88c
data/README.md CHANGED
@@ -104,23 +104,21 @@ The check runs once the app has started, after every class in `app/subscribers`
104
104
  registered. A subscriber anywhere else registers only once Rails has loaded its class,
105
105
  so keep subscribers in `app/subscribers`.
106
106
 
107
- ## Requiring every event to run inline
107
+ ## Requiring a pack's events to run inline
108
108
 
109
109
  A subscriber that refuses a change can only undo it when it runs inline, during the
110
- emit. A host that depends on that calls the event start check once the subscriber
111
- processors are registered:
110
+ emit. A host that depends on that names the event packs whose events must run inline:
112
111
 
113
112
  ```ruby
114
113
  # config/application.rb
115
- config.after_initialize do
116
- EventEngine::Subscribers.check_inline!(EventEngine::Subscribers.routes)
117
- end
114
+ config.event_engine_subscribers.inline_packs = [:console]
118
115
  ```
119
116
 
120
- The app then refuses to start when an event has no rule, when a rule names a processor
121
- nothing registered, or when any event is routed to `background`. The last error names
122
- every such event. A host that does not call it can route events to `background` as
123
- before.
117
+ When the app starts, the gem then refuses to start when an event has no rule, when a
118
+ rule names a processor nothing registered, or when an event in a named pack is routed to
119
+ `background`. The last error names every such event. Events in other packs may still
120
+ run in the background. With no packs named, which is the default, the gem runs no inline
121
+ check.
124
122
 
125
123
  ## A working example app
126
124
 
@@ -5,6 +5,9 @@ module EventEngine
5
5
  class Engine < ::Rails::Engine
6
6
  isolate_namespace EventEngine::Subscribers
7
7
 
8
+ config.event_engine_subscribers = ActiveSupport::OrderedOptions.new
9
+ config.event_engine_subscribers.inline_packs = []
10
+
8
11
  initializer "event_engine.subscribers.register_processor" do
9
12
  config.after_initialize do
10
13
  processor = Processor.new
@@ -18,6 +21,13 @@ module EventEngine
18
21
  config.after_initialize { Subscribers.check!(Subscribers.routes) }
19
22
  end
20
23
 
24
+ initializer "event_engine.subscribers.check_inline_packs", after: "event_engine.subscribers.register_processor" do |app|
25
+ config.after_initialize do
26
+ packs = app.config.event_engine_subscribers.inline_packs
27
+ Subscribers.check_inline!(Subscribers.routes, packs: packs) if packs.any?
28
+ end
29
+ end
30
+
21
31
  initializer "event_engine.subscribers.forget_unloaded_subscribers" do |app|
22
32
  app.reloader.before_class_unload { Registry.clear! }
23
33
  end
@@ -1,5 +1,5 @@
1
1
  module EventEngine
2
2
  module Subscribers
3
- VERSION = "0.3.0"
3
+ VERSION = "0.4.0"
4
4
  end
5
5
  end
@@ -25,12 +25,16 @@ module EventEngine
25
25
  true
26
26
  end
27
27
 
28
- def self.check_inline!(routes)
28
+ def self.check_inline!(routes, packs: nil)
29
29
  EventEngine.validate_rules!
30
30
  background = routes.reject { |_event_name, process_type| process_type == :inline }.keys
31
+ background = background.select { |event_name| packs.include?(pack_of(event_name)) } if packs
31
32
  raise BackgroundEventsError, background if background.any?
32
33
 
33
34
  true
34
35
  end
36
+
37
+ def self.pack_of(event_name) = EventEngine.schema_registry.latest_for(event_name).domain
38
+ private_class_method :pack_of
35
39
  end
36
40
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: event_engine-subscribers
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - tylercschneider