Module: ViewModel::AfterTransactionRunner

Included in:
ViewModel::ActiveRecord::Cache::CacheableView::CacheClearer
Defined in:
lib/view_model/after_transaction_runner.rb

Overview

Module implementing the behaviour of a AR post-transaction hook. After calling ‘add_to_transaction`, the abstract method `after_transaction` will be invoked by AR’s callbacks.

Instance Method Summary collapse

Instance Method Details

#add_to_transactionObject



32
33
34
35
36
37
38
39
# File 'lib/view_model/after_transaction_runner.rb', line 32

def add_to_transaction
  if connection.transaction_open?
    connection.add_transaction_record(self)
  else
    before_commit
    after_commit
  end
end

#after_commitObject



28
# File 'lib/view_model/after_transaction_runner.rb', line 28

def after_commit; end

#after_rollbackObject



30
# File 'lib/view_model/after_transaction_runner.rb', line 30

def after_rollback; end

#before_commitObject

Our simplified API



26
# File 'lib/view_model/after_transaction_runner.rb', line 26

def before_commit; end

#before_committed!Object



12
13
14
# File 'lib/view_model/after_transaction_runner.rb', line 12

def before_committed!
  before_commit
end

#committed!Object

Rails’ internal API



8
9
10
# File 'lib/view_model/after_transaction_runner.rb', line 8

def committed!(*)
  after_commit
end

#connectionObject

Override to tie to a specific connection.



42
43
44
# File 'lib/view_model/after_transaction_runner.rb', line 42

def connection
  ActiveRecord::Base.connection
end

#rolledback!Object



16
17
18
# File 'lib/view_model/after_transaction_runner.rb', line 16

def rolledback!(*)
  after_rollback
end

#trigger_transactional_callbacks?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/view_model/after_transaction_runner.rb', line 20

def trigger_transactional_callbacks?
  true
end