6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
# File 'lib/after_commit_changes.rb', line 6
def self.included(base)
base.before_commit do
rollup_mutations_for_transaction!
end
base.after_save do
@after_commit_saved_changes ||= []
@after_commit_saved_changes << [self.class.connection.open_transactions, saved_changes]
end
base.after_rollback do
if @after_commit_saved_changes
depth = self.class.connection.open_transactions
@after_commit_saved_changes.reject! { |entry_depth, _changes| entry_depth > depth }
@after_commit_saved_changes = nil if @after_commit_saved_changes.empty?
end
end
end
|