Class | StateMachine::TransitionCollection |
In: |
lib/state_machine/transition_collection.rb
|
Parent: | Array |
skip_actions | [R] | Whether to skip running the action for each transition‘s machine |
skip_after | [R] | Whether to skip running the after callbacks |
use_transaction | [R] | Whether transitions should wrapped around a transaction block |
Creates a new collection of transitions that can be run in parallel. Each transition must be for a different attribute.
Configuration options:
# File lib/state_machine/transition_collection.rb, line 22 22: def initialize(transitions = [], options = {}) 23: super(transitions) 24: 25: # Determine the validity of the transitions as a whole 26: @valid = all? 27: reject! {|transition| !transition} 28: 29: attributes = map {|transition| transition.attribute}.uniq 30: raise ArgumentError, 'Cannot perform multiple transitions in parallel for the same state machine attribute' if attributes.length != length 31: 32: assert_valid_keys(options, :actions, :after, :transaction) 33: options = {:actions => true, :after => true, :transaction => true}.merge(options) 34: @skip_actions = !options[:actions] 35: @skip_after = !options[:after] 36: @use_transaction = options[:transaction] 37: end
Runs each of the collection‘s transitions in parallel.
All transitions will run through the following steps:
If a block is passed to this method, that block will be called instead of invoking each transition‘s action.
# File lib/state_machine/transition_collection.rb, line 50 50: def perform(&block) 51: reset 52: 53: if valid? 54: if use_event_attributes? && !block_given? 55: each do |transition| 56: transition.transient = true 57: transition.machine.write(object, :event_transition, transition) 58: end 59: 60: run_actions 61: else 62: within_transaction do 63: catch(:halt) { run_callbacks(&block) } 64: rollback unless success? 65: end 66: end 67: end 68: 69: if actions.length == 1 && results.include?(actions.first) 70: results[actions.first] 71: else 72: success? 73: end 74: end