Module: AASM

Defined in:
lib/aasm.rb,
lib/event.rb,
lib/state.rb,
lib/version.rb,
lib/persistence.rb,
lib/state_machine.rb,
lib/state_transition.rb,
lib/persistence/active_record_persistence.rb

Defined Under Namespace

Modules: ClassMethods, Persistence, SupportingClasses, VERSION Classes: InvalidTransition, StateMachine, TransitionGuarded, UndefinedState

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object

:nodoc:



20
21
22
23
24
25
26
27
# File 'lib/aasm.rb', line 20

def self.included(base) #:nodoc:
  # TODO - need to ensure that a machine is being created because
  # AASM was either included or arrived at via inheritance.  It
  # cannot be both.
  base.extend AASM::ClassMethods
  AASM::Persistence.set_persistence(base)
  AASM::StateMachine[base] = AASM::StateMachine.new('')
end

.VersionObject



7
8
9
# File 'lib/aasm.rb', line 7

def self.Version
  '2.0.5.2'
end

Instance Method Details

#aasm_current_stateObject

Instance methods



88
89
90
91
92
93
94
95
96
# File 'lib/aasm.rb', line 88

def aasm_current_state
  return @aasm_current_state if @aasm_current_state

  if self.respond_to?(:aasm_read_state) || self.private_methods.include?('aasm_read_state')
    @aasm_current_state = aasm_read_state
  end
  return @aasm_current_state if @aasm_current_state
  self.class.aasm_initial_state
end

#aasm_eventObject



116
# File 'lib/aasm.rb', line 116

def aasm_event; @aasm_event; end

#aasm_event=(event) ⇒ Object

Added to allow forms to trigger events, perhaps I missed something, but this seemed neccesary -asoules



108
109
110
111
112
113
114
# File 'lib/aasm.rb', line 108

def aasm_event=(event)
  return if event.blank?
  if aasm_events_for_current_state.include?(event.to_sym)
    @aasm_event = event
    send(event)
  end
end

#aasm_events_for_current_state(context = :all) ⇒ Object



98
99
100
# File 'lib/aasm.rb', line 98

def aasm_events_for_current_state(context=:all)
  aasm_events_for_state(aasm_current_state, context)
end

#aasm_events_for_state(state, context = :all) ⇒ Object



102
103
104
105
# File 'lib/aasm.rb', line 102

def aasm_events_for_state(state, context=:all)
  events = self.class.aasm_events.values.select {|event| event.transitions_from_state?(state, context) }
  events.map {|event| event.name}
end