### Home Classes Methods

### In Files

- lib/state_machine/integrations/mongo_mapper/versions.rb
- lib/state_machine/integrations/active_model/observer_update.rb
- lib/state_machine/integrations/active_model/observer.rb
- lib/state_machine/integrations/active_model/versions.rb
- lib/state_machine/integrations/base.rb
- lib/state_machine/integrations/active_record/versions.rb
- lib/state_machine/integrations/active_record.rb
- lib/state_machine/integrations/mongo_mapper.rb
- lib/state_machine/integrations/active_model.rb
- lib/state_machine/integrations/mongoid.rb
- lib/state_machine/integrations/sequel/versions.rb
- lib/state_machine/integrations/data_mapper/observer.rb
- lib/state_machine/integrations/data_mapper/versions.rb
- lib/state_machine/integrations/mongoid/versions.rb
- lib/state_machine/integrations/sequel.rb
- lib/state_machine/integrations/data_mapper.rb
- lib/state_machine/integrations.rb

### Namespace

- MODULE StateMachine::Integrations::ActiveModel
- MODULE StateMachine::Integrations::ActiveRecord
- MODULE StateMachine::Integrations::Base
- MODULE StateMachine::Integrations::DataMapper
- MODULE StateMachine::Integrations::MongoMapper
- MODULE StateMachine::Integrations::Mongoid
- MODULE StateMachine::Integrations::Sequel

### Methods

- ::all
- ::find_by_name
- ::match
- ::match_ancestors

### 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::Integrations

Integrations allow state machines to take advantage of features within the context of a particular library. This is currently most useful with database libraries. For example, the various database integrations allow state machines to hook into features like:

- Saving

- Transactions

- Observers

- Scopes

- Callbacks

- Validation errors

This type of integration allows the user to work with state machines in a fashion similar to other object models in their application.

The integration interface is loosely defined by various unimplemented methods in the StateMachine::Machine class. See that class or the various built-in integrations for more information about how to define additional integrations.

### Public Class Methods

all() click to toggle source

Gets a list of all of the available integrations for use. This will always list the ActiveModel integration last.

## Example

    StateMachine::Integrations.all
    # => [StateMachine::Integrations::ActiveRecord, StateMachine::Integrations::DataMapper
    #     StateMachine::Integrations::Mongoid, StateMachine::Integrations::MongoMapper,
    #     StateMachine::Integrations::Sequel, StateMachine::Integrations::ActiveModel]

    # File lib/state_machine/integrations.rb, line 116
    def self.all
      constants = self.constants.map {|c| c.to_s}.select {|c| c != 'ActiveModel'}.sort << 'ActiveModel'
      constants.map {|c| const_get(c)}
    end

find_by_name(name) click to toggle source

Finds an integration with the given name. If the integration cannot be found, then a NameError exception will be raised.

## Examples

    StateMachine::Integrations.find_by_name(:active_record) # => StateMachine::Integrations::ActiveRecord
    StateMachine::Integrations.find_by_name(:active_model)  # => StateMachine::Integrations::ActiveModel
    StateMachine::Integrations.find_by_name(:data_mapper)   # => StateMachine::Integrations::DataMapper
    StateMachine::Integrations.find_by_name(:mongoid)       # => StateMachine::Integrations::Mongoid
    StateMachine::Integrations.find_by_name(:mongo_mapper)  # => StateMachine::Integrations::MongoMapper
    StateMachine::Integrations.find_by_name(:sequel)        # => StateMachine::Integrations::Sequel
    StateMachine::Integrations.find_by_name(:invalid)       # => StateMachine::IntegrationNotFound: :invalid is an invalid integration

    # File lib/state_machine/integrations.rb, line 103
    def self.find_by_name(name)
      all.detect {|integration| integration.integration_name == name} || raise(IntegrationNotFound.new(name))
    end

match(klass) click to toggle source

Attempts to find an integration that matches the given class. This will look through all of the built-in integrations under the StateMachine::Integrations namespace and find one that successfully matches the class.

## Examples

    class Vehicle
    end

    class ActiveModelVehicle
      include ActiveModel::Observing
      include ActiveModel::Validations
    end

    class ActiveRecordVehicle < ActiveRecord::Base
    end

    class DataMapperVehicle
      include DataMapper::Resource
    end

    class MongoidVehicle
      include Mongoid::Document
    end

    class MongoMapperVehicle
      include MongoMapper::Document
    end

    class SequelVehicle < Sequel::Model
    end

    StateMachine::Integrations.match(Vehicle)             # => nil
    StateMachine::Integrations.match(ActiveModelVehicle)  # => StateMachine::Integrations::ActiveModel
    StateMachine::Integrations.match(ActiveRecordVehicle) # => StateMachine::Integrations::ActiveRecord
    StateMachine::Integrations.match(DataMapperVehicle)   # => StateMachine::Integrations::DataMapper
    StateMachine::Integrations.match(MongoidVehicle)      # => StateMachine::Integrations::Mongoid
    StateMachine::Integrations.match(MongoMapperVehicle)  # => StateMachine::Integrations::MongoMapper
    StateMachine::Integrations.match(SequelVehicle)       # => StateMachine::Integrations::Sequel

    # File lib/state_machine/integrations.rb, line 75
    def self.match(klass)
      all.detect {|integration| integration.matches?(klass)}
    end

match_ancestors(ancestors) click to toggle source

Attempts to find an integration that matches the given list of ancestors. This will look through all of the built-in integrations under the StateMachine::Integrations namespace and find one that successfully matches one of the ancestors.

## Examples

    StateMachine::Integrations.match([])                    # => nil
    StateMachine::Integrations.match(['ActiveRecord::Base') # => StateMachine::Integrations::ActiveModel

    # File lib/state_machine/integrations.rb, line 87
    def self.match_ancestors(ancestors)
      all.detect {|integration| integration.matches_ancestors?(ancestors)}
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.