after_commit_everywhere 1.3.1 → 1.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/CHANGELOG.md +15 -0
- data/README.md +4 -2
- data/lib/after_commit_everywhere/version.rb +1 -1
- data/lib/after_commit_everywhere.rb +17 -3
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 749225d1d1a6000f08b986f6c2704767339fc576648811f4421fb7344b864761
|
4
|
+
data.tar.gz: af075362eeaa19f6e893d5fcefadd751f8cf7817bd310ddea0a024e49482100e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c816318efea508b86763b07f69b6164eab40edb52f5c95953e05c6dd7df1b2432b1a933e0bfa68605b7b67c3e99dbee6a3e7c4c30389214c7ed9bab5d6afa704
|
7
|
+
data.tar.gz: 4b20e061dfbd60ca6caef4da43ba1866c92a4c3be3418016da1f1f768f01321c99d19f024020d48139dd4320b0c0d21854554e15ee67bf0e9a6a1f3b072e21ad
|
data/CHANGELOG.md
CHANGED
@@ -4,6 +4,19 @@ All notable changes to this project will be documented in this file.
|
|
4
4
|
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
|
5
5
|
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
|
6
6
|
|
7
|
+
## 1.4.0 (2024-02-07)
|
8
|
+
|
9
|
+
### Added
|
10
|
+
|
11
|
+
- Ability to prepend callbacks to the head of callback queue using `prepend: true` option.
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
AfterCommitEverywhere.after_commit { puts "I'm second!" }
|
15
|
+
AfterCommitEverywhere.after_commit(prepend: true) { puts "I'm first!" }
|
16
|
+
```
|
17
|
+
|
18
|
+
See [Pull request #30](https://github.com/Envek/after_commit_everywhere/pull/30) by [@quentindemetz][] and [@A1090][].
|
19
|
+
|
7
20
|
## 1.3.1 (2023-06-21)
|
8
21
|
|
9
22
|
### Fixed
|
@@ -132,3 +145,5 @@ See [#11](https://github.com/Envek/after_commit_everywhere/issues/11) for discus
|
|
132
145
|
[@stokarenko]: https://github.com/stokarenko "Sergey Tokarenko"
|
133
146
|
[@lolripgg]: https://github.com/lolripgg "James Brewer"
|
134
147
|
[@jpcamara]: https://github.com/jpcamara "JP Camara"
|
148
|
+
[@quentindemetz]: https://github.com/quentindemetz "Quentin de Metz"
|
149
|
+
[@A1090]: https://github.com/A1090 "Tabac Andreina"
|
data/README.md
CHANGED
@@ -111,7 +111,7 @@ Will be executed right after transaction in which it have been declared was roll
|
|
111
111
|
|
112
112
|
If called outside transaction will raise an exception!
|
113
113
|
|
114
|
-
Please keep in mind ActiveRecord's [limitations for rolling back nested transactions](http://api.rubyonrails.org/classes/ActiveRecord/Transactions/ClassMethods.html#module-ActiveRecord::Transactions::ClassMethods-label-Nested+transactions). See [`in_transaction`](#in_transaction) for a workaround to this limitation.
|
114
|
+
Please keep in mind ActiveRecord's [limitations for rolling back nested transactions](http://api.rubyonrails.org/classes/ActiveRecord/Transactions/ClassMethods.html#module-ActiveRecord::Transactions::ClassMethods-label-Nested+transactions). See [`in_transaction`](#in_transaction) for a workaround to this limitation.
|
115
115
|
|
116
116
|
### Available helper methods
|
117
117
|
|
@@ -139,7 +139,7 @@ class ServiceObjectBtw
|
|
139
139
|
end
|
140
140
|
```
|
141
141
|
|
142
|
-
Our service object can run its database operations safely when run in isolation.
|
142
|
+
Our service object can run its database operations safely when run in isolation.
|
143
143
|
|
144
144
|
```rb
|
145
145
|
ServiceObjectBtw.new.call # This opens a new #transaction block
|
@@ -195,6 +195,8 @@ end
|
|
195
195
|
- `:warn_and_execute` to print warning and execute immediately
|
196
196
|
- `:raise` to raise an exception instead of executing
|
197
197
|
|
198
|
+
- `prepend` puts the callback at the head of the callback chain, instead of at the end.
|
199
|
+
|
198
200
|
### FAQ
|
199
201
|
|
200
202
|
#### Does it works with transactional_test or DatabaseCleaner
|
@@ -39,11 +39,13 @@ module AfterCommitEverywhere
|
|
39
39
|
# @param callback [#call] Callback to be executed
|
40
40
|
# @return void
|
41
41
|
def after_commit(
|
42
|
+
prepend: false,
|
42
43
|
connection: nil,
|
43
44
|
without_tx: EXECUTE,
|
44
45
|
&callback
|
45
46
|
)
|
46
47
|
register_callback(
|
48
|
+
prepend: prepend,
|
47
49
|
connection: connection,
|
48
50
|
name: __method__,
|
49
51
|
callback: callback,
|
@@ -64,6 +66,7 @@ module AfterCommitEverywhere
|
|
64
66
|
# @param callback [#call] Callback to be executed
|
65
67
|
# @return void
|
66
68
|
def before_commit(
|
69
|
+
prepend: false,
|
67
70
|
connection: nil,
|
68
71
|
without_tx: WARN_AND_EXECUTE,
|
69
72
|
&callback
|
@@ -73,6 +76,7 @@ module AfterCommitEverywhere
|
|
73
76
|
end
|
74
77
|
|
75
78
|
register_callback(
|
79
|
+
prepend: prepend,
|
76
80
|
connection: connection,
|
77
81
|
name: __method__,
|
78
82
|
callback: callback,
|
@@ -90,8 +94,9 @@ module AfterCommitEverywhere
|
|
90
94
|
# @param callback [#call] Callback to be executed
|
91
95
|
# @return void
|
92
96
|
# @raise [NotInTransaction] if called outside transaction.
|
93
|
-
def after_rollback(connection: nil, &callback)
|
97
|
+
def after_rollback(prepend: false, connection: nil, &callback)
|
94
98
|
register_callback(
|
99
|
+
prepend: prepend,
|
95
100
|
connection: connection,
|
96
101
|
name: __method__,
|
97
102
|
callback: callback,
|
@@ -100,7 +105,7 @@ module AfterCommitEverywhere
|
|
100
105
|
end
|
101
106
|
|
102
107
|
# @api private
|
103
|
-
def register_callback(connection: nil, name:, without_tx:, callback:)
|
108
|
+
def register_callback(prepend:, connection: nil, name:, without_tx:, callback:)
|
104
109
|
raise ArgumentError, "Provide callback to #{name}" unless callback
|
105
110
|
|
106
111
|
unless in_transaction?(connection)
|
@@ -119,7 +124,16 @@ module AfterCommitEverywhere
|
|
119
124
|
|
120
125
|
connection ||= default_connection
|
121
126
|
wrap = Wrap.new(connection: connection, "#{name}": callback)
|
122
|
-
|
127
|
+
|
128
|
+
if prepend
|
129
|
+
# Hacking ActiveRecord's transaction internals to prepend our callback
|
130
|
+
# See https://github.com/rails/rails/blob/f0d433bb46ac233ec7fd7fae48f458978908d905/activerecord/lib/active_record/connection_adapters/abstract/transaction.rb#L148-L156
|
131
|
+
records = connection.current_transaction.instance_variable_get(:@records)
|
132
|
+
records = connection.current_transaction.instance_variable_set(:@records, []) if records.nil?
|
133
|
+
records.unshift(wrap)
|
134
|
+
else
|
135
|
+
connection.add_transaction_record(wrap)
|
136
|
+
end
|
123
137
|
end
|
124
138
|
|
125
139
|
# Helper method to determine whether we're currently in transaction or not
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: after_commit_everywhere
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrey Novikov
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-02-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -246,7 +246,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
246
246
|
- !ruby/object:Gem::Version
|
247
247
|
version: '0'
|
248
248
|
requirements: []
|
249
|
-
rubygems_version: 3.
|
249
|
+
rubygems_version: 3.5.3
|
250
250
|
signing_key:
|
251
251
|
specification_version: 4
|
252
252
|
summary: Executes code after database commit wherever you want in your application
|