effective_resources 1.8.24 → 1.8.25
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f3c3734459a525f8630d12e30d9e96b1e5c83e9d35cd94abecf6dcd791da2db1
|
4
|
+
data.tar.gz: 3c5d96f0b62dac483b987f16b97e7d9a003105ec28a1b09a6c556e77d379bae0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fcc4eb1793ace16a2f70c59fccba103f3398721eb6784dbb55d182e2320f131d11a2fae15a6a621e2ec7aa1fbe2f98074bdd66ff652fed943e835271a83cf611
|
7
|
+
data.tar.gz: 5eb1dded2b45631cd646bfda6a75d5d3cbcbf89e35f8d817d28aad950ba6e84274d30627b963e276392926bd337aec687f917a435aa11f9fc313d19395c6f6c2
|
@@ -1,5 +1,6 @@
|
|
1
1
|
# EffectiveAfterCommit
|
2
2
|
#
|
3
|
+
# Execute code after the ActiveRecord transaction has committed
|
3
4
|
# Inspired by https://github.com/Envek/after_commit_everywhere
|
4
5
|
#
|
5
6
|
# This is automatically included into ActiveRecord::Base
|
@@ -16,7 +17,6 @@ module EffectiveAfterCommit
|
|
16
17
|
|
17
18
|
def before_commit(connection: self.class.connection, &callback)
|
18
19
|
raise(NotImplementedError, "#{__method__} works only with Rails 5.0+") if ActiveRecord::VERSION::MAJOR < 5
|
19
|
-
|
20
20
|
Effective::AfterCommit.register_callback(connection: connection, name: __method__, callback: callback, no_tx_action: :warn_and_execute)
|
21
21
|
end
|
22
22
|
|
@@ -1,8 +1,7 @@
|
|
1
1
|
module Effective
|
2
2
|
class AfterCommit
|
3
3
|
|
4
|
-
def initialize(
|
5
|
-
@connection = connection
|
4
|
+
def initialize(**handlers)
|
6
5
|
@handlers = handlers
|
7
6
|
end
|
8
7
|
|
@@ -26,10 +25,6 @@ module Effective
|
|
26
25
|
@handlers[:after_rollback]&.call
|
27
26
|
end
|
28
27
|
|
29
|
-
def add_to_transaction(*)
|
30
|
-
@connection.add_transaction_record(self)
|
31
|
-
end
|
32
|
-
|
33
28
|
def self.register_callback(connection:, name:, no_tx_action:, callback:)
|
34
29
|
raise ArgumentError, "#{name} expected a block" unless callback
|
35
30
|
|
@@ -45,7 +40,7 @@ module Effective
|
|
45
40
|
end
|
46
41
|
end
|
47
42
|
|
48
|
-
after_commit = Effective::AfterCommit.new(
|
43
|
+
after_commit = Effective::AfterCommit.new("#{name}": callback)
|
49
44
|
connection.add_transaction_record(after_commit)
|
50
45
|
end
|
51
46
|
|