Class: ActsAsMentionable::TransactionCallbacks

Inherits:
Object
  • Object
show all
Defined in:
lib/acts_as_mentionable/transaction_callbacks.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(on_committed_block, on_rolled_back_block) ⇒ TransactionCallbacks

Returns a new instance of TransactionCallbacks.



29
30
31
32
# File 'lib/acts_as_mentionable/transaction_callbacks.rb', line 29

def initialize on_committed_block, on_rolled_back_block
  @on_committed_block = on_committed_block
  @on_rolled_back_block = on_rolled_back_block
end

Instance Attribute Details

#on_committed_blockObject (readonly)

Returns the value of attribute on_committed_block.



27
28
29
# File 'lib/acts_as_mentionable/transaction_callbacks.rb', line 27

def on_committed_block
  @on_committed_block
end

#on_rolled_back_blockObject (readonly)

Returns the value of attribute on_rolled_back_block.



27
28
29
# File 'lib/acts_as_mentionable/transaction_callbacks.rb', line 27

def on_rolled_back_block
  @on_rolled_back_block
end

Class Method Details

.on_committed(&block) ⇒ Object



4
5
6
7
8
9
10
# File 'lib/acts_as_mentionable/transaction_callbacks.rb', line 4

def on_committed &block
  if current_transaction.open?
    add_transaction_record new(block, nil)
  else
    yield
  end
end

.on_rolled_back(&block) ⇒ Object



12
13
14
# File 'lib/acts_as_mentionable/transaction_callbacks.rb', line 12

def on_rolled_back &block
  add_transaction_record new(nil, block)
end

Instance Method Details

#committed!(_should_run_callbacks = true) ⇒ Object



34
35
36
# File 'lib/acts_as_mentionable/transaction_callbacks.rb', line 34

def committed! _should_run_callbacks = true
  on_committed_block&.call
end

#rolledback!(_force_restore_state = false, _should_run_callbacks = true) ⇒ Object



38
39
40
# File 'lib/acts_as_mentionable/transaction_callbacks.rb', line 38

def rolledback! _force_restore_state = false, _should_run_callbacks = true
  on_rolled_back_block&.call
end