Module: ViewModel::AfterTransactionRunner

Extended by:
ActiveSupport::Concern
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



49
50
51
52
53
54
55
56
# File 'lib/view_model/after_transaction_runner.rb', line 49

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

#after_commitObject



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

def after_commit; end

#after_rollbackObject



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

def after_rollback; end

#before_commitObject

Our simplified API



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

def before_commit; end

#before_committed!Object



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

def before_committed!
  before_commit
end

#committed!Object

Rails’ internal API



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

def committed!(*)
  after_commit
end

#connectionObject

Override to tie to a specific connection.



59
60
61
# File 'lib/view_model/after_transaction_runner.rb', line 59

def connection
  ActiveRecord::Base.connection
end

#rolledback!Object



33
34
35
# File 'lib/view_model/after_transaction_runner.rb', line 33

def rolledback!(*)
  after_rollback
end

#trigger_transactional_callbacks?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/view_model/after_transaction_runner.rb', line 37

def trigger_transactional_callbacks?
  true
end