2016-01-13 17:02:49 -05:00
|
|
|
class MultiTransitioner
|
|
|
|
include AASM
|
|
|
|
|
|
|
|
attr_accessor :can_run
|
|
|
|
|
|
|
|
def initialize
|
|
|
|
@can_run = false
|
|
|
|
end
|
|
|
|
|
|
|
|
aasm do
|
|
|
|
state :sleeping, :initial => true
|
|
|
|
state :running
|
|
|
|
state :dancing
|
2016-09-06 13:02:18 -04:00
|
|
|
state :dead
|
2016-01-13 17:02:49 -05:00
|
|
|
|
|
|
|
event :start do
|
|
|
|
transitions :from => :sleeping, :to => :running, guard: :runnable?
|
|
|
|
transitions :from => :sleeping, :to => :dancing
|
|
|
|
end
|
2016-09-06 13:02:18 -04:00
|
|
|
|
|
|
|
event :sleep do
|
|
|
|
transitions to: :sleeping, if: :alive?
|
|
|
|
transitions to: :dead, from: [:running, :dancing]
|
|
|
|
end
|
2016-01-13 17:02:49 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def runnable?
|
|
|
|
@can_run
|
|
|
|
end
|
2016-09-06 13:02:18 -04:00
|
|
|
|
|
|
|
def alive?
|
|
|
|
true
|
|
|
|
end
|
2016-01-13 17:02:49 -05:00
|
|
|
end
|