eventish 0.5.0 → 0.5.1
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 +4 -4
- data/README.md +27 -2
- data/lib/eventish/active_job_event.rb +6 -0
- data/lib/eventish/simple_event.rb +6 -0
- data/lib/eventish/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5074ba83f3c48572d1074e1f212c2220a7fe98f21868d2a331439b642fb44745
|
4
|
+
data.tar.gz: dcb4ff6ea905f77414c74c369c803e582c2e143b50b59f8903e7eec91a4d0538
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fdbf059ef0be7568fa12a5df0fde30920adb881f5e5df40b2bb0b130dad3e620b5f415fdf9ceb3f0c18075bf77996606653ef40a982558546cfb1f708864c40f
|
7
|
+
data.tar.gz: 7f8395c61e2662fd4b801ef99577d4b8085b5b0d484867444ef12a25bf7df2657d68a5edf329b70de0b48196839424fa90cba933e6c3f3f848be05b1f5547a40
|
data/README.md
CHANGED
@@ -11,8 +11,15 @@ Main features:
|
|
11
11
|
- _composable_: just require the components that you need;
|
12
12
|
- with [adapters](#adapters): support ActiveSupport::Notifications and Wisper for pub/sub events;
|
13
13
|
- with [async events](#async-events): support ActiveJob for events background execution;
|
14
|
-
- with [callbacks wrapper](#callbacks): support ActiveRecord callbacks
|
15
|
-
- with [plugins](#plugins): a simple logger and a Rails logger are included
|
14
|
+
- with [callbacks wrapper](#callbacks): support ActiveRecord callbacks;
|
15
|
+
- with [plugins](#plugins): a simple logger and a Rails logger are included;
|
16
|
+
- with conditional event execution (overriding `callable?`).
|
17
|
+
|
18
|
+
This component can be useful to:
|
19
|
+
- decouple callbacks from the side-effect;
|
20
|
+
- permit to test the side-effects in isolation;
|
21
|
+
- permit to spy/block the side-effects;
|
22
|
+
- permit to execute the side-effects from other contexts.
|
16
23
|
|
17
24
|
Please :star: if you like it.
|
18
25
|
|
@@ -199,6 +206,24 @@ end
|
|
199
206
|
|
200
207
|
Plugins can also be configured for single events overriding _before_event_ and _after_event_.
|
201
208
|
|
209
|
+
### Conditional events
|
210
|
+
|
211
|
+
Optionally an event can override the `callable?` method to define preconditions on the execution of the `call` method.
|
212
|
+
|
213
|
+
Example:
|
214
|
+
|
215
|
+
```rb
|
216
|
+
class TestEvent < Eventish::SimpleEvent
|
217
|
+
def callable?(target)
|
218
|
+
target.ready?
|
219
|
+
end
|
220
|
+
|
221
|
+
def call(target, _options = {})
|
222
|
+
puts '> A test event'
|
223
|
+
end
|
224
|
+
end
|
225
|
+
```
|
226
|
+
|
202
227
|
## Do you like it? Star it!
|
203
228
|
|
204
229
|
If you use this component just star it. A developer is more motivated to improve a project when there is some interest.
|
@@ -6,6 +6,10 @@ module Eventish
|
|
6
6
|
raise NotImplementedError
|
7
7
|
end
|
8
8
|
|
9
|
+
def callable?(_target)
|
10
|
+
true
|
11
|
+
end
|
12
|
+
|
9
13
|
def perform(target, args)
|
10
14
|
self.class.before_event.each { |plugin| plugin.call(target, args, event: self, hook: :before) }
|
11
15
|
call(target, args)
|
@@ -17,6 +21,8 @@ module Eventish
|
|
17
21
|
include Eventish::EventApi
|
18
22
|
|
19
23
|
def trigger(target, args, &_block)
|
24
|
+
return unless new.callable?(target)
|
25
|
+
|
20
26
|
perform_later(target, args)
|
21
27
|
end
|
22
28
|
end
|
@@ -6,11 +6,17 @@ module Eventish
|
|
6
6
|
raise NotImplementedError
|
7
7
|
end
|
8
8
|
|
9
|
+
def callable?(_target)
|
10
|
+
true
|
11
|
+
end
|
12
|
+
|
9
13
|
class << self
|
10
14
|
include EventApi
|
11
15
|
|
12
16
|
def trigger(target, args, &block)
|
13
17
|
event = new
|
18
|
+
return unless event.callable?(target)
|
19
|
+
|
14
20
|
before_event.each { |plugin| plugin.call(target, args, event: event, hook: :before, &block) }
|
15
21
|
event.call(target, args, &block)
|
16
22
|
after_event.each { |plugin| plugin.call(target, args, event: event, hook: :after, &block) }
|
data/lib/eventish/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: eventish
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mattia Roccoberton
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-06-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: appraisal
|