3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
# File 'lib/after_commit/connection_adapters.rb', line 3
def self.included(base)
base.class_eval do
def commit_db_transaction_with_callback
commit_db_transaction_without_callback
trigger_after_commit_callbacks
trigger_after_commit_on_create_callbacks
trigger_after_commit_on_update_callbacks
trigger_after_commit_on_destroy_callbacks
end
alias_method_chain :commit_db_transaction, :callback
def rollback_db_transaction_with_callback
rollback_db_transaction_without_callback
AfterCommit.committed_records = []
AfterCommit.committed_records_on_create = []
AfterCommit.committed_records_on_update = []
AfterCommit.committed_records_on_destroy = []
end
alias_method_chain :rollback_db_transaction, :callback
protected
def trigger_after_commit_callbacks
if AfterCommit.committed_records.any?
AfterCommit.committed_records.each do |record|
begin
record.after_commit_callback
rescue
end
end
end
AfterCommit.committed_records = []
end
def trigger_after_commit_on_create_callbacks
if AfterCommit.committed_records_on_create.any?
AfterCommit.committed_records_on_create.each do |record|
begin
record.after_commit_on_create_callback
rescue
end
end
end
AfterCommit.committed_records_on_create = []
end
def trigger_after_commit_on_update_callbacks
if AfterCommit.committed_records_on_update.any?
AfterCommit.committed_records_on_update.each do |record|
begin
record.after_commit_on_update_callback
rescue
end
end
end
AfterCommit.committed_records_on_update = []
end
def trigger_after_commit_on_destroy_callbacks
if AfterCommit.committed_records_on_destroy.any?
AfterCommit.committed_records_on_destroy.each do |record|
begin
record.after_commit_on_destroy_callback
rescue
end
end
end
AfterCommit.committed_records_on_destroy = []
end
end
end
|