Module: AASM

Defined in:
lib/alexrevin-aasm_numerical.rb,
lib/alexrevin-aasm_numerical/aasm.rb,
lib/alexrevin-aasm_numerical/version.rb,
lib/alexrevin-aasm_numerical/persistence/active_record_persistence.rb

Defined Under Namespace

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

Constant Summary collapse

VERSION =
"2.3.1"

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object

:nodoc:



8
9
10
11
12
13
14
15
16
# File 'lib/alexrevin-aasm_numerical/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
 super
end

Instance Method Details

#aasm_current_stateObject

Instance methods



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

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



98
99
100
101
102
103
104
105
106
107
108
# File 'lib/alexrevin-aasm_numerical/aasm.rb', line 98

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



110
111
112
# File 'lib/alexrevin-aasm_numerical/aasm.rb', line 110

def aasm_events_for_current_state
  aasm_events_for_state(aasm_current_state)
end

#aasm_events_for_state(state) ⇒ Object



120
121
122
123
# File 'lib/alexrevin-aasm_numerical/aasm.rb', line 120

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

#aasm_permissible_events_for_current_stateObject

filters the results of events_for_current_state so that only those that are really currently possible (given transition guards) are shown.



116
117
118
# File 'lib/alexrevin-aasm_numerical/aasm.rb', line 116

def aasm_permissible_events_for_current_state
  aasm_events_for_current_state.select{ |e| self.send(("may_" + e.to_s + "?").to_sym) }
end

#human_stateObject



125
126
127
# File 'lib/alexrevin-aasm_numerical/aasm.rb', line 125

def human_state
  AASM::Localizer.new.human_state(self)
end