Module: AASM

Defined in:
lib/aasm.rb,
lib/aasm/aasm.rb,
lib/aasm/persistence/active_record_persistence.rb

Defined Under Namespace

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object

:nodoc:



8
9
10
11
12
13
14
# File 'lib/aasm/aasm.rb', line 8

def self.included(base) #:nodoc:
  base.extend AASM::ClassMethods
  AASM::Persistence.set_persistence(base)
  unless AASM::StateMachine[base]
    AASM::StateMachine[base] = AASM::StateMachine.new('')
  end
end

Instance Method Details

#aasm_current_stateObject

Instance methods



75
76
77
78
79
80
81
82
83
84
# File 'lib/aasm/aasm.rb', line 75

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

  aasm_enter_initial_state
end

#aasm_enter_initial_stateObject



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

def aasm_enter_initial_state
  state_name = aasm_determine_state_name(self.class.aasm_initial_state)
  state = aasm_state_object_for_state(state_name)

  state.call_action(:before_enter, self)
  state.call_action(:enter, self)
  self.aasm_current_state = state_name
  state.call_action(:after_enter, self)

  state_name
end

#aasm_events_for_current_stateObject



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

def aasm_events_for_current_state
  aasm_events_for_state(aasm_current_state)
end

#aasm_events_for_state(state) ⇒ Object



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

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