event_engine-subscribers 0.2.0 → 0.3.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:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 77ec2b6b5c9768d1968ead2a2d567e796a91747036be8d6c407137a36997c781
|
|
4
|
+
data.tar.gz: 4f97fd5b867ca07942c082c3e37a65e4a0bb452c6e7c4d59fd409561ccb9ea23
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b806c0dbe05a8c57a1d3b1c0cd0fbe7937d015f5822d37c3f5feafd083d922a5f528b871564aaa8259866d8f0bd6ca4b90af63351788b8521f4baadf57346201
|
|
7
|
+
data.tar.gz: fcc63467dcf27dc0021304dd36821de214c30f9eff44efca1f3f2cd6a9b5a59cbe6f43693547f28e86bc4b0f7dfa949f8d912ee25c914bd1ff35328ba9aed617
|
data/README.md
CHANGED
|
@@ -104,6 +104,24 @@ 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
|
|
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 calls the event start check once the subscriber
|
|
111
|
+
processors are registered:
|
|
112
|
+
|
|
113
|
+
```ruby
|
|
114
|
+
# config/application.rb
|
|
115
|
+
config.after_initialize do
|
|
116
|
+
EventEngine::Subscribers.check_inline!(EventEngine::Subscribers.routes)
|
|
117
|
+
end
|
|
118
|
+
```
|
|
119
|
+
|
|
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.
|
|
124
|
+
|
|
107
125
|
## A working example app
|
|
108
126
|
|
|
109
127
|
[**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
|
|
@@ -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,13 @@ module EventEngine
|
|
|
23
24
|
|
|
24
25
|
true
|
|
25
26
|
end
|
|
27
|
+
|
|
28
|
+
def self.check_inline!(routes)
|
|
29
|
+
EventEngine.validate_rules!
|
|
30
|
+
background = routes.reject { |_event_name, process_type| process_type == :inline }.keys
|
|
31
|
+
raise BackgroundEventsError, background if background.any?
|
|
32
|
+
|
|
33
|
+
true
|
|
34
|
+
end
|
|
26
35
|
end
|
|
27
36
|
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.
|
|
4
|
+
version: 0.3.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
|