eventish 0.3.2 → 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 +4 -4
- data/README.md +32 -4
- data/lib/eventish/active_job_event.rb +3 -0
- data/lib/eventish/event_api.rb +8 -0
- data/lib/eventish/plugins/logger.rb +13 -0
- data/lib/eventish/plugins/rails_logger.rb +13 -0
- data/lib/eventish/simple_event.rb +5 -1
- data/lib/eventish/version.rb +1 -1
- data/lib/eventish.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b680cd59cf6faa489efed4b75bd284699213c249ff2d29c82f62d67facf634a2
|
4
|
+
data.tar.gz: 52bb544e7348bf01b9d0b60b236123488a0bdc5cb4e3138dac817292710517a3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 69cc41ae3fb78d9cee65ee21cd71b480534fc0381acedf41bf6d4e26c3d5fe6ec9377359ed44b01b3834af2e2f4a35a39462e2be39f47c672290fc49585e08e7
|
7
|
+
data.tar.gz: 98718a8527924fe2e6396fdba0170b5998398aa4427f9b7af92fbf103e4c4a631da4ad9a349ec8131905ec651d3b5225d654200e01445312536313fb68ada425
|
data/README.md
CHANGED
@@ -2,14 +2,16 @@
|
|
2
2
|
|
3
3
|
[](https://badge.fury.io/rb/eventish)
|
4
4
|
[](https://github.com/blocknotes/eventish/actions/workflows/main.yml)
|
5
|
+
[](https://github.com/blocknotes/eventish/actions/workflows/linters.yml)
|
5
6
|
|
6
7
|
Yet another opinionated events library which proposes a simple API to handle... events 🎉
|
7
8
|
|
8
9
|
The main features:
|
9
10
|
- _composable_: just require the components that you need;
|
10
|
-
- with
|
11
|
-
- with
|
12
|
-
- with
|
11
|
+
- with [adapters](#adapters): support ActiveSupport::Notifications for pub/sub events;
|
12
|
+
- with [async events](#async-events): support ActiveJob for background execution;
|
13
|
+
- with [callbacks wrapper](#callbacks): support ActiveRecord.
|
14
|
+
- with [plugins](#plugins): logger and Rails logger included.
|
13
15
|
|
14
16
|
## Install
|
15
17
|
|
@@ -52,7 +54,7 @@ end
|
|
52
54
|
|
53
55
|
For a complete example please take a look at the [dummy app](spec/dummy) in the specs.
|
54
56
|
|
55
|
-
###
|
57
|
+
### Adapters
|
56
58
|
|
57
59
|
Only _ActiveSupport_ is supported for now.
|
58
60
|
|
@@ -143,6 +145,32 @@ end
|
|
143
145
|
|
144
146
|
The related callback will be setup by the wrapper and the specified event class will be invoked accordingly.
|
145
147
|
|
148
|
+
### Plugins
|
149
|
+
|
150
|
+
A plugins system is available for custom processing, a logger and a Rails logger are included in the gem.
|
151
|
+
|
152
|
+
```rb
|
153
|
+
# initializer setup
|
154
|
+
require 'eventish/plugins/rails_logger' # without rails_ for a simple stdout logger
|
155
|
+
|
156
|
+
Eventish.setup do |config|
|
157
|
+
config.before_event = [Eventish::Plugins::RailsLogger]
|
158
|
+
config.after_event = [Eventish::Plugins::RailsLogger]
|
159
|
+
end
|
160
|
+
```
|
161
|
+
|
162
|
+
A sample plugin:
|
163
|
+
|
164
|
+
```rb
|
165
|
+
module Eventish::Plugins::RailsLogger
|
166
|
+
class << self
|
167
|
+
def call(target, _args, event:, hook: nil, &_block)
|
168
|
+
Rails.logger.debug "EVENT: #{hook} #{event.class.event_name} on #{target.inspect}"
|
169
|
+
end
|
170
|
+
end
|
171
|
+
end
|
172
|
+
```
|
173
|
+
|
146
174
|
## Do you like it? Star it!
|
147
175
|
|
148
176
|
If you use this component just star it. A developer is more motivated to improve a project when there is some interest.
|
@@ -7,7 +7,10 @@ module Eventish
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def perform(target, args)
|
10
|
+
self.class.before_event.each { |plugin| plugin.call(target, args, event: self, hook: :before) }
|
10
11
|
call(target, args)
|
12
|
+
self.class.after_event.each { |plugin| plugin.call(target, args, event: self, hook: :after) }
|
13
|
+
self
|
11
14
|
end
|
12
15
|
|
13
16
|
class << self
|
data/lib/eventish/event_api.rb
CHANGED
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Eventish
|
4
|
+
module Plugins
|
5
|
+
class Logger
|
6
|
+
class << self
|
7
|
+
def call(target, _args, event:, hook: nil, &_block)
|
8
|
+
puts "[#{Time.now}] EVENT: #{hook} #{event.class.event_name} on #{target.inspect}"
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Eventish
|
4
|
+
module Plugins
|
5
|
+
class RailsLogger
|
6
|
+
class << self
|
7
|
+
def call(target, _args, event:, hook: nil, &_block)
|
8
|
+
Rails.logger.debug "EVENT: #{hook} #{event.class.event_name} on #{target.inspect}"
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -10,7 +10,11 @@ module Eventish
|
|
10
10
|
include EventApi
|
11
11
|
|
12
12
|
def trigger(target, args, &block)
|
13
|
-
|
13
|
+
event = new
|
14
|
+
before_event.each { |plugin| plugin.call(target, args, event: event, hook: :before, &block) }
|
15
|
+
event.call(target, args, &block)
|
16
|
+
after_event.each { |plugin| plugin.call(target, args, event: event, hook: :after, &block) }
|
17
|
+
event
|
14
18
|
end
|
15
19
|
end
|
16
20
|
end
|
data/lib/eventish/version.rb
CHANGED
data/lib/eventish.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.
|
4
|
+
version: 0.4.0
|
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-
|
11
|
+
date: 2022-05-21 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: A simple and composable event library
|
14
14
|
email: mat@blocknot.es
|
@@ -23,6 +23,8 @@ files:
|
|
23
23
|
- lib/eventish/active_record/callback.rb
|
24
24
|
- lib/eventish/adapters/active_support.rb
|
25
25
|
- lib/eventish/event_api.rb
|
26
|
+
- lib/eventish/plugins/logger.rb
|
27
|
+
- lib/eventish/plugins/rails_logger.rb
|
26
28
|
- lib/eventish/simple_event.rb
|
27
29
|
- lib/eventish/version.rb
|
28
30
|
homepage: https://github.com/blocknotes/eventish
|