after_commit_everywhere 1.3.1 → 1.5.0

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: 6b63aab224d26cf40ba71632ebc055bd458bd3c72c87234715d1d8020f661247
4
- data.tar.gz: b558770a87644ee346a8361419ea9d0e616062da4873427d260dc8e428d545b4
3
+ metadata.gz: c801e905947621b60d9409be76cfb81d5d8b33f9c875cb120b143a91b4f87736
4
+ data.tar.gz: 90b6d70641c070a3866ab70929c41b9729b8693878a3bdba203a690eef6312a5
5
5
  SHA512:
6
- metadata.gz: 99d19cdc3ba272ad5a7c6a47b232d2cd6d5fa012889cd270763d154cf559d2b504b34ba650917a8618f073897a46e4e4fec79293092d05e66aa435d21179037a
7
- data.tar.gz: 7169e814084435d36a231cc5b2a3c7b11268a3e24913826b00fefe87ceaddea2c2299208616938d51ee245eca60136a654f8ec02664e30c3466f59b43f82f62d
6
+ metadata.gz: 3ce2d472754e15c17b4c52795c1a9f7a98b0021ab2ffc0c7d5120fd7ff0a2f24c83d0e1177c35ff30c517a6501219716b5ef1c49c1ff386b947561a092ab674c
7
+ data.tar.gz: a4e4ee45d289bba022eef8f3da4b08fa2da1f23f4643197a1338bfd734da9f7d3b1e55f8ec87d8183ba448022af957238f848baef5d66383ace9d55fa739dd76
data/CHANGELOG.md CHANGED
@@ -4,6 +4,27 @@ 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.5.0 (2024-12-09)
8
+
9
+ ### Added
10
+
11
+ - Ability to propagate exception for multiple `after_commit` callbacks within transaction. Should handle exception inside callback to avoid stopping other callbacks.
12
+
13
+ [Pull request #35](https://github.com/Envek/after_commit_everywhere/pull/35) by [@kevink1103](). Also see discussion at [#34](https://github.com/Envek/after_commit_everywhere/issues/34).
14
+
15
+ ## 1.4.0 (2024-02-07)
16
+
17
+ ### Added
18
+
19
+ - Ability to prepend callbacks to the head of callback queue using `prepend: true` option.
20
+
21
+ ```ruby
22
+ AfterCommitEverywhere.after_commit { puts "I'm second!" }
23
+ AfterCommitEverywhere.after_commit(prepend: true) { puts "I'm first!" }
24
+ ```
25
+
26
+ See [Pull request #30](https://github.com/Envek/after_commit_everywhere/pull/30) by [@quentindemetz][] and [@A1090][].
27
+
7
28
  ## 1.3.1 (2023-06-21)
8
29
 
9
30
  ### Fixed
@@ -132,3 +153,6 @@ See [#11](https://github.com/Envek/after_commit_everywhere/issues/11) for discus
132
153
  [@stokarenko]: https://github.com/stokarenko "Sergey Tokarenko"
133
154
  [@lolripgg]: https://github.com/lolripgg "James Brewer"
134
155
  [@jpcamara]: https://github.com/jpcamara "JP Camara"
156
+ [@quentindemetz]: https://github.com/quentindemetz "Quentin de Metz"
157
+ [@A1090]: https://github.com/A1090 "Tabac Andreina"
158
+ [@kevink1103]: https://github.com/kevink1103 "Kevin (bum)"
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
@@ -28,6 +28,11 @@ Gem::Specification.new do |spec|
28
28
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
29
29
  spec.require_paths = ["lib"]
30
30
 
31
+ spec.metadata["homepage_uri"] = spec.homepage
32
+ spec.metadata["source_code_uri"] = spec.homepage
33
+ spec.metadata["changelog_uri"] = "https://github.com/Envek/after_commit_everywhere/blob/master/CHANGELOG.md"
34
+ spec.metadata["bug_tracker_uri"] = "https://github.com/Envek/after_commit_everywhere/issues"
35
+
31
36
  spec.add_dependency "activerecord", ">= 4.2"
32
37
  spec.add_dependency "activesupport"
33
38
  spec.add_development_dependency "appraisal"
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module AfterCommitEverywhere
4
- VERSION = "1.3.1"
4
+ VERSION = "1.5.0"
5
5
  end
@@ -23,8 +23,10 @@ module AfterCommitEverywhere
23
23
  true
24
24
  end
25
25
 
26
- def committed!(*)
27
- @handlers[:after_commit]&.call
26
+ def committed!(should_run_callbacks: true)
27
+ if should_run_callbacks
28
+ @handlers[:after_commit]&.call
29
+ end
28
30
  end
29
31
 
30
32
  def rolledback!(*)
@@ -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
- connection.add_transaction_record(wrap)
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.3.1
4
+ version: 1.5.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: 2023-06-21 00:00:00.000000000 Z
11
+ date: 2024-12-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -230,7 +230,11 @@ files:
230
230
  homepage: https://github.com/Envek/after_commit_everywhere
231
231
  licenses:
232
232
  - MIT
233
- metadata: {}
233
+ metadata:
234
+ homepage_uri: https://github.com/Envek/after_commit_everywhere
235
+ source_code_uri: https://github.com/Envek/after_commit_everywhere
236
+ changelog_uri: https://github.com/Envek/after_commit_everywhere/blob/master/CHANGELOG.md
237
+ bug_tracker_uri: https://github.com/Envek/after_commit_everywhere/issues
234
238
  post_install_message:
235
239
  rdoc_options: []
236
240
  require_paths:
@@ -246,7 +250,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
246
250
  - !ruby/object:Gem::Version
247
251
  version: '0'
248
252
  requirements: []
249
- rubygems_version: 3.1.6
253
+ rubygems_version: 3.5.22
250
254
  signing_key:
251
255
  specification_version: 4
252
256
  summary: Executes code after database commit wherever you want in your application