event_engine-subscribers 0.2.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: 34965b10a7789582de233120f7e16c220292225c732605797c7dd2759f84d070
4
- data.tar.gz: 3936714ca836690e78228fdfe66c5be51b5c7a7826264ea5f745ea696c16a277
3
+ metadata.gz: 9911cefcbfa87b20178f615e68e88cef8f57da763ad42fcdf10a3f7f1b9d7be9
4
+ data.tar.gz: 1aa83bfbbea17ba4b3d2555f08509545f487e94d38abc52409de1a97bfa52109
5
5
  SHA512:
6
- metadata.gz: '08c34c7ddcdef975a9c8af1f2289e55bf13bcaa7426e18544bb92bebe80f3acd1f927a9f207d05b130a4481b4aed632506f0e8e24c7fe3384e3cefbf62821088'
7
- data.tar.gz: a750d52e0fc9a50cde6feded5f5ac782a027f9618ce4104a7fc2c231bdc403f8e6e607f8e9326297796e6fc4aab740f4912a3e458536acd65ea85d04fc808a1f
6
+ metadata.gz: 64e5c8652616821523641c4ffa5e17afb165e052847cde405c42f9ba2e852ed90a5c77add76ba3d6315e4fe230b97c280ff6213db5671c18a94e41757d957f82
7
+ data.tar.gz: 6b420c78274b70abf4cda7d544074e692e400409dac035937204b2270a0a2605b9a3f63198d46b0c9201c49cd3406aab5a6d1f789de28defe4c69aaf4f6fd88c
data/README.md CHANGED
@@ -104,6 +104,22 @@ 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 a pack's events to run inline
108
+
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 names the event packs whose events must run inline:
111
+
112
+ ```ruby
113
+ # config/application.rb
114
+ config.event_engine_subscribers.inline_packs = [:console]
115
+ ```
116
+
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.
122
+
107
123
  ## A working example app
108
124
 
109
125
  [**DYB-Development/event_engine_example**](https://github.com/DYB-Development/event_engine_example)
@@ -0,0 +1,9 @@
1
+ module EventEngine
2
+ module Subscribers
3
+ class BackgroundEventsError < StandardError
4
+ def initialize(event_names)
5
+ super("These events are routed to run in the background, where a refusal cannot undo the change: #{event_names.join(", ")}")
6
+ end
7
+ end
8
+ end
9
+ end
@@ -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.2.0"
3
+ VERSION = "0.4.0"
4
4
  end
5
5
  end
@@ -4,6 +4,7 @@ require "event_engine/subscribers/registry"
4
4
  require "event_engine/subscribers/base"
5
5
  require "event_engine/subscribers/processor"
6
6
  require "event_engine/subscribers/unsubscribed_events_error"
7
+ require "event_engine/subscribers/background_events_error"
7
8
 
8
9
  module EventEngine
9
10
  module Subscribers
@@ -23,5 +24,17 @@ module EventEngine
23
24
 
24
25
  true
25
26
  end
27
+
28
+ def self.check_inline!(routes, packs: nil)
29
+ EventEngine.validate_rules!
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
32
+ raise BackgroundEventsError, background if background.any?
33
+
34
+ true
35
+ end
36
+
37
+ def self.pack_of(event_name) = EventEngine.schema_registry.latest_for(event_name).domain
38
+ private_class_method :pack_of
26
39
  end
27
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.2.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - tylercschneider
@@ -81,6 +81,7 @@ files:
81
81
  - app/jobs/event_engine/subscribers/dispatch_subscribers_job.rb
82
82
  - app/views/layouts/event_engine/subscribers/application.html.erb
83
83
  - lib/event_engine/subscribers.rb
84
+ - lib/event_engine/subscribers/background_events_error.rb
84
85
  - lib/event_engine/subscribers/base.rb
85
86
  - lib/event_engine/subscribers/engine.rb
86
87
  - lib/event_engine/subscribers/processor.rb