Module: StateMachines::AfterTransitionCommit
- Defined in:
- lib/state_machines/after_transition_commit.rb,
lib/state_machines/after_transition_commit/version.rb
Constant Summary collapse
- VERSION =
"0.2.0"
Instance Method Summary collapse
- #add_after_transition_commit_callback ⇒ Object
- #after_transition_commit(*args, &after_transistion_block) ⇒ Object
Instance Method Details
#add_after_transition_commit_callback ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/state_machines/after_transition_commit.rb', line 7 def add_after_transition_commit_callback owner_class.after_commit do if @blocks_to_call_after_commit.present? @blocks_to_call_after_commit.each do |after_commit_block| after_commit_block.call(self) end @blocks_to_call_after_commit = [] end end end |
#after_transition_commit(*args, &after_transistion_block) ⇒ Object
19 20 21 22 23 24 25 26 |
# File 'lib/state_machines/after_transition_commit.rb', line 19 def after_transition_commit(*args, &after_transistion_block) state_machine = self state_machine.after_transition(*args) do |object, _transition| blocks_to_call_after_commit = object.instance_variable_get(:@blocks_to_call_after_commit) || [] blocks_to_call_after_commit << after_transistion_block object.instance_variable_set(:@blocks_to_call_after_commit, blocks_to_call_after_commit) end end |