after_commit 1.0.8 → 1.0.9
Sign up to get free protection for your applications and to get access to all the features.
- data/README.textile +2 -0
- data/lib/after_commit/after_savepoint.rb +27 -15
- data/lib/after_commit/connection_adapters.rb +31 -13
- metadata +9 -20
data/README.textile
CHANGED
@@ -62,3 +62,5 @@ This version (maintained by Pat Allan) includes the following patches:
|
|
62
62
|
* Keeping callbacks focused on the correct transactions ("Benjamin Stein":http://benjaminste.in/)
|
63
63
|
* Using savepoints for test helper ("Lars Klevan":http://www.linkedin.com/in/larsklevan and "Joel Chippindale":http://blog.monkeysthumb.org/)
|
64
64
|
* Only tracking objects from classes that have appropriate callbacks; Adding @after/before_commit_on_save@ to cover creates and updates but not destroys ("Jason Weathered":http://jasoncodes.com/)
|
65
|
+
* Fixing up exception handling and savepoints in the test helper, and cleaning up successful transactions correctly ("Identified":https://github.com/Identified).
|
66
|
+
* Improved JRuby support ("Kevin Menard":https://github.com/nirvdrum)
|
@@ -34,9 +34,23 @@ module AfterCommit
|
|
34
34
|
module TestConnectionAdapters
|
35
35
|
def self.included(base)
|
36
36
|
base.class_eval do
|
37
|
+
|
38
|
+
def after_callback_transaction_committed?
|
39
|
+
committed = (Thread.current[:after_callback_committed] || {})[unique_transaction_key]
|
40
|
+
return !committed.nil? && committed
|
41
|
+
end
|
42
|
+
|
43
|
+
def after_callback_mark_committed committed
|
44
|
+
(Thread.current[:after_callback_committed] ||= {})[unique_transaction_key] = committed
|
45
|
+
end
|
46
|
+
|
47
|
+
def after_callback_cleanup_committed
|
48
|
+
(Thread.current[:after_callback_committed] ||= {})[unique_transaction_key] = nil
|
49
|
+
end
|
50
|
+
|
37
51
|
def release_savepoint_with_callback
|
38
52
|
increment_transaction_pointer
|
39
|
-
|
53
|
+
after_callback_mark_committed false
|
40
54
|
begin
|
41
55
|
trigger_before_commit_callbacks
|
42
56
|
trigger_before_commit_on_create_callbacks
|
@@ -45,21 +59,15 @@ module AfterCommit
|
|
45
59
|
trigger_before_commit_on_destroy_callbacks
|
46
60
|
|
47
61
|
release_savepoint_without_callback
|
48
|
-
|
49
|
-
|
62
|
+
after_callback_mark_committed true
|
50
63
|
trigger_after_commit_callbacks
|
51
64
|
trigger_after_commit_on_create_callbacks
|
52
65
|
trigger_after_commit_on_save_callbacks
|
53
66
|
trigger_after_commit_on_update_callbacks
|
54
67
|
trigger_after_commit_on_destroy_callbacks
|
55
|
-
rescue
|
56
|
-
unless committed
|
57
|
-
decrement_transaction_pointer
|
58
|
-
rollback_to_savepoint
|
59
|
-
increment_transaction_pointer
|
60
|
-
end
|
61
|
-
ensure
|
62
68
|
AfterCommit.cleanup(self)
|
69
|
+
after_callback_cleanup_committed
|
70
|
+
ensure
|
63
71
|
decrement_transaction_pointer
|
64
72
|
end
|
65
73
|
end
|
@@ -71,13 +79,17 @@ module AfterCommit
|
|
71
79
|
def rollback_to_savepoint_with_callback
|
72
80
|
increment_transaction_pointer
|
73
81
|
begin
|
74
|
-
|
75
|
-
|
76
|
-
|
82
|
+
# Only rollback if we have not already released rollback
|
83
|
+
unless after_callback_transaction_committed?
|
84
|
+
trigger_before_rollback_callbacks
|
85
|
+
rollback_to_savepoint_without_callback
|
86
|
+
trigger_after_rollback_callbacks
|
87
|
+
end
|
77
88
|
ensure
|
78
89
|
AfterCommit.cleanup(self)
|
79
|
-
|
80
|
-
|
90
|
+
after_callback_cleanup_committed
|
91
|
+
decrement_transaction_pointer
|
92
|
+
end
|
81
93
|
end
|
82
94
|
alias_method_chain :rollback_to_savepoint, :callback
|
83
95
|
end
|
@@ -2,18 +2,35 @@ module AfterCommit
|
|
2
2
|
module ConnectionAdapters
|
3
3
|
def self.included(base)
|
4
4
|
base.class_eval do
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
5
|
+
|
6
|
+
if respond_to?(:transaction)
|
7
|
+
def transaction_with_callback(*args, &block)
|
8
|
+
# @disable_rollback is set to false at the start of the
|
9
|
+
# outermost call to #transaction. After committing, it is
|
10
|
+
# set to true to prevent exceptions causing a spurious
|
11
|
+
# rollback.
|
12
|
+
outermost_call = @disable_rollback.nil?
|
13
|
+
@disable_rollback = false if outermost_call
|
14
|
+
transaction_without_callback(*args, &block)
|
15
|
+
ensure
|
16
|
+
@disable_rollback = nil if outermost_call
|
17
|
+
end
|
18
|
+
alias_method_chain :transaction, :callback
|
19
|
+
|
20
|
+
elsif respond_to?(:begin_db_transaction)
|
21
|
+
def begin_db_transaction_with_callback(*args, &block)
|
22
|
+
# @disable_rollback is set to false at the start of the
|
23
|
+
# outermost call to #transaction. After committing, it is
|
24
|
+
# set to true to prevent exceptions causing a spurious
|
25
|
+
# rollback.
|
26
|
+
outermost_call = @disable_rollback.nil?
|
27
|
+
@disable_rollback = false if outermost_call
|
28
|
+
begin_db_transaction_without_callback(*args, &block)
|
29
|
+
ensure
|
30
|
+
@disable_rollback = nil if outermost_call
|
31
|
+
end
|
32
|
+
alias_method_chain :begin_db_transaction, :callback
|
33
|
+
end
|
17
34
|
|
18
35
|
# The commit_db_transaction method gets called when the outermost
|
19
36
|
# transaction finishes and everything inside commits. We want to
|
@@ -53,7 +70,7 @@ module AfterCommit
|
|
53
70
|
AfterCommit.cleanup(self)
|
54
71
|
decrement_transaction_pointer unless @already_decremented
|
55
72
|
end
|
56
|
-
end
|
73
|
+
end
|
57
74
|
alias_method_chain :commit_db_transaction, :callback
|
58
75
|
|
59
76
|
# In the event the transaction fails and rolls back, nothing inside
|
@@ -183,6 +200,7 @@ module AfterCommit
|
|
183
200
|
Thread.current[:after_commit_pointer] ||= 0
|
184
201
|
Thread.current[:after_commit_pointer] -= 1
|
185
202
|
end
|
203
|
+
|
186
204
|
end
|
187
205
|
end
|
188
206
|
end
|
metadata
CHANGED
@@ -1,12 +1,8 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: after_commit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
prerelease:
|
5
|
-
|
6
|
-
- 1
|
7
|
-
- 0
|
8
|
-
- 8
|
9
|
-
version: 1.0.8
|
4
|
+
prerelease:
|
5
|
+
version: 1.0.9
|
10
6
|
platform: ruby
|
11
7
|
authors:
|
12
8
|
- Nick Muerdter
|
@@ -16,7 +12,7 @@ autorequire:
|
|
16
12
|
bindir: bin
|
17
13
|
cert_chain: []
|
18
14
|
|
19
|
-
date:
|
15
|
+
date: 2011-06-08 00:00:00 +01:00
|
20
16
|
default_executable:
|
21
17
|
dependencies:
|
22
18
|
- !ruby/object:Gem::Dependency
|
@@ -27,11 +23,10 @@ dependencies:
|
|
27
23
|
requirements:
|
28
24
|
- - <
|
29
25
|
- !ruby/object:Gem::Version
|
30
|
-
segments:
|
31
|
-
- 3
|
32
|
-
- 0
|
33
|
-
- 0
|
34
26
|
version: 3.0.0
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 1.15.6
|
35
30
|
type: :runtime
|
36
31
|
version_requirements: *id001
|
37
32
|
- !ruby/object:Gem::Dependency
|
@@ -42,8 +37,6 @@ dependencies:
|
|
42
37
|
requirements:
|
43
38
|
- - ">="
|
44
39
|
- !ruby/object:Gem::Version
|
45
|
-
segments:
|
46
|
-
- 0
|
47
40
|
version: "0"
|
48
41
|
type: :development
|
49
42
|
version_requirements: *id002
|
@@ -72,8 +65,8 @@ homepage: http://github.com/freelancing-god/after_commit
|
|
72
65
|
licenses: []
|
73
66
|
|
74
67
|
post_install_message:
|
75
|
-
rdoc_options:
|
76
|
-
|
68
|
+
rdoc_options: []
|
69
|
+
|
77
70
|
require_paths:
|
78
71
|
- lib
|
79
72
|
required_ruby_version: !ruby/object:Gem::Requirement
|
@@ -81,21 +74,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
81
74
|
requirements:
|
82
75
|
- - ">="
|
83
76
|
- !ruby/object:Gem::Version
|
84
|
-
segments:
|
85
|
-
- 0
|
86
77
|
version: "0"
|
87
78
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
88
79
|
none: false
|
89
80
|
requirements:
|
90
81
|
- - ">="
|
91
82
|
- !ruby/object:Gem::Version
|
92
|
-
segments:
|
93
|
-
- 0
|
94
83
|
version: "0"
|
95
84
|
requirements: []
|
96
85
|
|
97
86
|
rubyforge_project:
|
98
|
-
rubygems_version: 1.
|
87
|
+
rubygems_version: 1.6.2
|
99
88
|
signing_key:
|
100
89
|
specification_version: 3
|
101
90
|
summary: after_commit callback for ActiveRecord
|