class Stately
state_machine :state, initial: :pending do
state :approved
state :declined
event :approve do
transition pending: :approved
end
event :decline do
transition all => :declined
end
end
end
stately = Stately.new
stately.state
#=> :pending
stately.state_events
#=> [ :approve, :decline ]
stately.approve
stately.state_events
#=> [ :decline ]
싶은 것은 ... 실수로 예외 (ALL 이벤트를 참조하는 것보다 훨씬 좁은 범위)가 발생합니다 이벤트 다음은이 작업을 수행 할 수 있습니다 트리거에서 자신을 방지하는 경우
stately = Stately.new
stately.state
#=> :pending
stately.can_approve?
#=> true
stately.can_decline?
#=> true
stately.approve
stately.can_approve?
#=> false
stately.can_decline?
#=> true
transition_for를 사용하여 무엇을 사용 하시겠습니까? 그걸 벗어나기를 바라는거야? – AndyV
다음 호출 가능한 상태를 알아야합니다. – rtacconi