eventish 0.3.0 → 0.3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 965405052bda0cb9903d4a447c91e5db89c8b98a868ded8428ee0399652680bd
4
- data.tar.gz: 4608f89362bd42919071b404d428c8a44178d608a51ae0c0eb2aeb0b9a3d40ee
3
+ metadata.gz: 8f5572d1bca258f0f1c9bd4e09e3743f99bf3045c82013c9742e1b06cfb3c590
4
+ data.tar.gz: abe5bdf2cbe1998404c21686ee97758681be8e038c0af03c67b7be1cbed2c8c5
5
5
  SHA512:
6
- metadata.gz: 78839ea7b019d89e6587692faa575e345c9b72eae8355833cb374a5b7906cedd97ebcc74e4e61db1ecf9ea3c4764f5de7eeacac0a79bd6448c080f341ef33db3
7
- data.tar.gz: 9b88eb7b02e330c68449cb7e978c8b40c6bc0a19cab874bd082fbf897ef61a9ec67ad3d2be866b3936d0370f777f158d423a414d3f469a4656facdfb8d201cb1
6
+ metadata.gz: 885eb9228852f4d143a52ca2db3b622eead0bb9c57bc47fecb8ce29ce9694488973151a1bcaf07df2783192aa362dd3626c200ca36a39afc721a6f5c22cc6222
7
+ data.tar.gz: e86ca0a3133a144c709a3a1cc76b2ba777d5995a8068ba202b6570bc4c31ab14e73fea390e3898825276bbc97651dfcdecb978af2266880f47219e810fc00d03
data/README.md CHANGED
@@ -8,7 +8,8 @@ Yet another opinionated events library which proposes a simple API to handle...
8
8
  The main features:
9
9
  - _composable_: just require the components that you need;
10
10
  - with _adapters_: support ActiveSupport::Notifications for pub/sub events;
11
- - with _async events_: support ActiveJob for background execution.
11
+ - with _async events_: support ActiveJob for background execution;
12
+ - with _callbacks_ wrapper: support ActiveRecord.
12
13
 
13
14
  ## Install
14
15
 
@@ -123,6 +124,25 @@ module Notifications
123
124
  end
124
125
  ```
125
126
 
127
+ ### Callbacks
128
+
129
+ Only for ActiveRecord, callbacks wrapper are available with the postfix `_event` (ex. `after_commit_event SomeEvent`).
130
+
131
+ ```rb
132
+ # initializer setup
133
+ require 'eventish/active_record/callback'
134
+ ```
135
+
136
+ ```rb
137
+ class SomeModel < ActiveRecord::Base
138
+ extend ::Eventish::ActiveRecord::Callback
139
+
140
+ before_validation_event SomeBeforeValidationEvent
141
+ end
142
+ ```
143
+
144
+ The related callback will be setup by the wrapper and the specified event class will be invoked accordingly.
145
+
126
146
  ## Do you like it? Star it!
127
147
 
128
148
  If you use this component just star it. A developer is more motivated to improve a project when there is some interest.
@@ -0,0 +1,107 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Eventish
4
+ module ActiveRecord
5
+ module Callback
6
+ # Init events
7
+ def after_initialize_event
8
+ before_validation -> { ::Eventish.publish(event, self) }
9
+ end
10
+
11
+ def after_find_event
12
+ before_validation -> { ::Eventish.publish(event, self) }
13
+ end
14
+
15
+ # Validation events
16
+ def before_validation_event(event)
17
+ before_validation -> { ::Eventish.publish(event, self) }
18
+ end
19
+
20
+ def after_validation_event(event)
21
+ after_validation -> { ::Eventish.publish(event, self) }
22
+ end
23
+
24
+ # Create events
25
+ def before_create_event(event)
26
+ before_create -> { ::Eventish.publish(event, self) }
27
+ end
28
+
29
+ def around_create_event(event)
30
+ around_create -> { ::Eventish.publish(event, self) }
31
+ end
32
+
33
+ def after_create_event(event)
34
+ after_create -> { ::Eventish.publish(event, self) }
35
+ end
36
+
37
+ # Update events
38
+ def before_update_event(event)
39
+ before_update -> { ::Eventish.publish(event, self) }
40
+ end
41
+
42
+ def around_update_event(event)
43
+ around_update -> { ::Eventish.publish(event, self) }
44
+ end
45
+
46
+ def after_update_event(event)
47
+ after_update -> { ::Eventish.publish(event, self) }
48
+ end
49
+
50
+ # Save events
51
+ def before_save_event(event)
52
+ before_save -> { ::Eventish.publish(event, self) }
53
+ end
54
+
55
+ def around_save_event(event)
56
+ around_save -> { ::Eventish.publish(event, self) }
57
+ end
58
+
59
+ def after_save_event(event)
60
+ after_save -> { ::Eventish.publish(event, self) }
61
+ end
62
+
63
+ # Destroy events
64
+ def before_destroy_event(event)
65
+ before_destroy -> { ::Eventish.publish(event, self) }
66
+ end
67
+
68
+ def around_destroy_event(event)
69
+ around_destroy -> { ::Eventish.publish(event, self) }
70
+ end
71
+
72
+ def after_destroy_event(event)
73
+ after_destroy -> { ::Eventish.publish(event, self) }
74
+ end
75
+
76
+ # Commit events
77
+ def after_commit_event(event)
78
+ after_commit -> { ::Eventish.publish(event, self) }
79
+ end
80
+
81
+ def after_save_commit_event(event)
82
+ after_save_commit -> { ::Eventish.publish(event, self) }
83
+ end
84
+
85
+ def after_create_commit_event(event)
86
+ after_create_commit -> { ::Eventish.publish(event, self) }
87
+ end
88
+
89
+ def after_update_commit_event(event)
90
+ after_update_commit -> { ::Eventish.publish(event, self) }
91
+ end
92
+
93
+ def after_destroy_commit_event(event)
94
+ after_destroy_commit -> { ::Eventish.publish(event, self) }
95
+ end
96
+
97
+ def after_rollback_event(event)
98
+ after_rollback -> { ::Eventish.publish(event, self) }
99
+ end
100
+
101
+ # Touch events
102
+ def after_touch_event(event)
103
+ after_touch -> { ::Eventish.publish(event, self) }
104
+ end
105
+ end
106
+ end
107
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Eventish # :nodoc:
4
- VERSION = '0.3.0'
4
+ VERSION = '0.3.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.3.0
4
+ version: 0.3.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-18 00:00:00.000000000 Z
11
+ date: 2022-05-19 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A simple and composable event library
14
14
  email: mat@blocknot.es
@@ -20,6 +20,7 @@ files:
20
20
  - README.md
21
21
  - lib/eventish.rb
22
22
  - lib/eventish/active_job_event.rb
23
+ - lib/eventish/active_record/callback.rb
23
24
  - lib/eventish/adapters/active_support.rb
24
25
  - lib/eventish/event_api.rb
25
26
  - lib/eventish/simple_event.rb