lib/acts_as_state_machine.rb
# Configuration options are
#
# * +column+ - specifies the column name to use for keeping the state (default: state)
# * +initial+ - specifies an initial state for newly created objects (required)
Configuration options are
+column+ - specifies the column name to use for keeping the state (default: state)
+initial+ - specifies an initial state for newly created objects (required)
Configuration options are + column + - specifies the column name to use for keeping the state ( default : state ) + initial + - specifies an initial state for newly created objects ( required )
def acts_as_state_machine(opts)
      raise NoInitialState unless opts[:initial]
      class_attribute :states
      class_attribute :initial_state
      class_attribute :transition_table
      class_attribute :event_table
      class_attribute :state_column
      class_attribute :record_state_timestamps
      self.states = {}
      self.initial_state = opts[:initial]
      self.transition_table = {}
      self.event_table = {}
      self.state_column = opts[:column] || 'state'
      record_timestamp = (opts[:record_state_timestamps] || opts[:record_state_timestamps].nil?) ? true : false
      self.record_state_timestamps = record_timestamp
      scope(:in_state, lambda { |*qstates|
        raise InvalidState if (qstates - self.states.keys).size > 0
        where(self.state_column.to_sym => qstates)
      }) do
        def not_in_state(*args)
          raise "Can't use 'in_state' named_scope with 'not_in_state' named scope"
        end
      end
      scope(:not_in_state, lambda { |*states|
        raise InvalidState if (qstates - self.states.keys).size > 0
        where("#{self.state_column} NOT IN (?)",states)
      }) do
        def in_state(*args)
          raise "Can't use 'in_state' named_scope with 'not_in_state' named scope"
        end
      end
      before_create               :set_initial_state
      after_create                :run_initial_state_actions
    end
def acts_as_state_machine ( opts ) raise NoInitialState unless opts [ :initial ] class_attribute :states class_attribute :initial_state class_attribute :transition_table class_attribute :event_table class_attribute :state_column class_attribute :record_state_timestamps self . states = { } self . initial_state = opts [ :initial ] self . transition_table = { } self . event_table = { } self . state_column = opts [ :column ] || 'state' record_timestamp = ( opts [ :record_state_timestamps ] || opts [ :record_state_timestamps ] . nil? ) ? true : false self . record_state_timestamps = record_timestamp scope ( :in_state , lambda { | * qstates | raise InvalidState if ( qstates - self . states . keys ) . size > 0 where ( self . state_column . to_sym => qstates ) } ) do def not_in_state ( * args ) raise "Can't use 'in_state' named_scope with 'not_in_state' named scope" end end scope ( :not_in_state , lambda { | * states | raise InvalidState if ( qstates - self . states . keys ) . size > 0 where ( "#{self.state_column} NOT IN (?)" , states ) } ) do def in_state ( * args ) raise "Can't use 'in_state' named_scope with 'not_in_state' named scope" end end before_create :set_initial_state after_create :run_initial_state_actions end
Configuration options are
 +column+ - specifies the column name to use for keeping the state (default: state)
 +initial+ - specifies an initial state for newly created objects (required)
Configuration options are + column + - specifies the column name to use for keeping the state ( default : state ) + initial + - specifies an initial state for newly created objects ( required )
# cattr_reader  :initial_state # cattr_reader  :state_column # cattr_reader  :transition_table # cattr_reader  :event_table # Adding a named scope that allows objects to be searched by one or more states          
opts
<not_specific>