ほぼREADMEのまま
aasm/aasm: AASM - State machines for Ruby classes (plain Ruby, ActiveRecord, Mongoid)
require 'aasm'
class Job
include AASM
aasm do
state :sleeping, initial: true
state :running, :cleaning
event :run do
transitions from: :sleeping, to: :running
end
event :clean do
transitions from: :running, to: :cleaning
end
event :sleep do
transitions from: [:running, :cleaning], to: :sleeping
end
after_all_transitions :log_status_change
end
def log_status_change
puts "changing from #{aasm.from_state} to #{aasm.to_state} (event: #{aasm.current_event})"
end
end
job = Job.new
# => #<Job:0x00007fb0d9f80750>
job.run
# changing from sleeping to running (event: run)
job.sleep
# changing from running to sleeping (event: sleep)
Original by Github issue
チャットメンバー募集
何か質問、悩み事、相談などあればLINEオープンチャットもご利用ください。