eventish 0.5.0 → 0.5.1

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: 419b6aafd21ffe1e4c9041549dc80b77fe7973975732a44feeac183f28d8f474
4
- data.tar.gz: 50e7f43233ee05c86c930807677cdee82a21471b6d4f4c4a037ea1062e6f3127
3
+ metadata.gz: 5074ba83f3c48572d1074e1f212c2220a7fe98f21868d2a331439b642fb44745
4
+ data.tar.gz: dcb4ff6ea905f77414c74c369c803e582c2e143b50b59f8903e7eec91a4d0538
5
5
  SHA512:
6
- metadata.gz: b768c6c9baaac52a7b3bd841569714727a43527d90956881645e17b11afc5be65e14bfec6424d4a877f12d7294dc4a69edaf94a55b62b4da7f9bb133d1d69c41
7
- data.tar.gz: a272f0d0420ae08b627be7fcb975d7051af6f7662b2089f91b4719a1b97fab70fd3cc7872031fba83ccb8d61881953f08d921476b4918cd9dfff82be05d6272b
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) }
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Eventish # :nodoc:
4
- VERSION = '0.5.0'
4
+ VERSION = '0.5.1'
5
5
  end
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.0
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-05-31 00:00:00.000000000 Z
11
+ date: 2022-06-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: appraisal