### Home Classes Methods

### In Files

- lib/state_machine/transition_collection.rb

### Parent

Array

### Methods

- ::new
- #perform

### Included Modules

- StateMachine::Assertions

### Files

- LICENSE

### Class/Module Index

Quicksearch

- StateMachine
- StateMachine::AllMatcher
- StateMachine::Assertions
- StateMachine::AttributeTransitionCollection
- StateMachine::BlacklistMatcher
- StateMachine::Branch
- StateMachine::Callback
- StateMachine::ClassMethods
- StateMachine::Error
- StateMachine::EvalHelpers
- StateMachine::Event
- StateMachine::EventCollection
- StateMachine::Graph
- StateMachine::InstanceMethods
- StateMachine::IntegrationNotFound
- StateMachine::Integrations
- StateMachine::Integrations::ActiveModel
- StateMachine::Integrations::ActiveModel::Observer
- StateMachine::Integrations::ActiveModel::ObserverUpdate
- StateMachine::Integrations::ActiveRecord
- StateMachine::Integrations::Base
- StateMachine::Integrations::Base::ClassMethods
- StateMachine::Integrations::DataMapper
- StateMachine::Integrations::DataMapper::Observer
- StateMachine::Integrations::MongoMapper
- StateMachine::Integrations::Mongoid
- StateMachine::Integrations::Sequel
- StateMachine::InvalidEvent
- StateMachine::InvalidParallelTransition
- StateMachine::InvalidTransition
- StateMachine::LoopbackMatcher
- StateMachine::Machine
- StateMachine::MachineCollection
- StateMachine::MacroMethods
- StateMachine::Matcher
- StateMachine::MatcherHelpers
- StateMachine::NodeCollection
- StateMachine::Path
- StateMachine::PathCollection
- StateMachine::RailsEngine
- StateMachine::State
- StateMachine::StateCollection
- StateMachine::StateContext
- StateMachine::Transition
- StateMachine::TransitionCollection
- StateMachine::WhitelistMatcher
- StateMachine::YARD
- StateMachine::YARD::Handlers
- StateMachine::YARD::Handlers::Base
- StateMachine::YARD::Handlers::Event
- StateMachine::YARD::Handlers::Machine
- StateMachine::YARD::Handlers::State
- StateMachine::YARD::Handlers::Transition
- Object

No matching classes.

# StateMachine::TransitionCollection

Represents a collection of transitions in a state machine

### Attributes

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

### Public Class Methods

new(transitions = [], options = {}) click to toggle source

Creates a new collection of transitions that can be run in parallel. Each transition must be for a different attribute.

Configuration options:

- `:actions` - Whether to run the action configured for each transition

- `:after` - Whether to run after callbacks

- `:transaction` - Whether to wrap transitions within a transaction

    # File lib/state_machine/transition_collection.rb, line 22
    def initialize(transitions = [], options = {})
      super(transitions)

      # Determine the validity of the transitions as a whole
      @valid = all?
      reject! {|transition| !transition}

      attributes = map {|transition| transition.attribute}.uniq
      raise ArgumentError, 'Cannot perform multiple transitions in parallel for the same state machine attribute' if attributes.length != length

      assert_valid_keys(options, :actions, :after, :transaction)
      options = {:actions => true, :after => true, :transaction => true}.merge(options)
      @skip_actions = !options[:actions]
      @skip_after = !options[:after]
      @use_transaction = options[:transaction]
    end

### Public Instance Methods

perform(&block) click to toggle source

Runs each of the collection's transitions in parallel.

All transitions will run through the following steps:

1. Before callbacks

2. Persist state

3. Invoke action

4. After callbacks (if configured)

5. Rollback (if action is unsuccessful)

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
    def perform(&block)
      reset

      if valid?
        if use_event_attributes? && !block_given?
          each do |transition|
            transition.transient = true
            transition.machine.write(object, :event_transition, transition)
          end

          run_actions
        else
          within_transaction do
            catch(:halt) { run_callbacks(&block) }
            rollback unless success?
          end
        end
      end

      if actions.length == 1 && results.include?(actions.first)
        results[actions.first]
      else
        success?
      end
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.