Sha256: 8b3816c0ae1d9e500dc9fe313a7b50096573cda49ab24e690e73da88b494f0f1
Contents?: true
Size: 966 Bytes
Versions: 1
Compression:
Stored size: 966 Bytes
Contents
require 'active_record' module ActiveRecord::AfterTransaction module Methods def self.included(klass) klass.class_eval do after_commit :execute_after_transaction after_rollback :clear_after_transaction end end def after_transaction(&block) return block.call unless self.class.connection.open_transactions @after_transaction_queue ||= [] @after_transaction_queue.push block logger && logger.debug("Push #{block}") end def execute_after_transaction queue = @after_transaction_queue if !queue.empty? logger && logger.debug("Execute the queue") queue = queue.dup clear_after_transaction queue.each do |block| logger && logger.debug("Execute #{block}") block.call end end end def clear_after_transaction logger && logger.debug("Clear the queue") @after_transaction_queue.clear end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
activerecord-after-transaction-0.1.1 | lib/activerecord-after-transaction/methods.rb |