Module: AfterCommit::Connection
- Defined in:
- lib/versions/after_commit.rb
Class Method Summary collapse
Instance Method Summary collapse
- #after_commit(&block) ⇒ Object
- #commit_db_transaction_with_after_commit ⇒ Object
- #transaction_with_after_commit(*args, &block) ⇒ Object
Class Method Details
.included(base) ⇒ Object
18 19 20 21 |
# File 'lib/versions/after_commit.rb', line 18 def self.included(base) base.alias_method_chain :commit_db_transaction, :after_commit base.alias_method_chain :transaction, :after_commit end |
Instance Method Details
#after_commit(&block) ⇒ Object
23 24 25 26 27 28 29 30 31 |
# File 'lib/versions/after_commit.rb', line 23 def after_commit(&block) if block_given? if open_transactions == 0 raise Exception.new("'after_commit' should only be used inside a transaction") else (@after_commit ||= []) << block end end end |
#commit_db_transaction_with_after_commit ⇒ Object
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/versions/after_commit.rb', line 33 def commit_db_transaction_with_after_commit after_commit_actions = @after_commit @after_commit = nil commit_db_transaction_without_after_commit if after_commit_actions after_commit_actions.each do |block| block.call end end end |
#transaction_with_after_commit(*args, &block) ⇒ Object
44 45 46 47 48 |
# File 'lib/versions/after_commit.rb', line 44 def transaction_with_after_commit(*args, &block) transaction_without_after_commit(*args, &block) ensure @after_commit = nil if open_transactions == 0 end |