Created
November 4, 2011 16:33
-
-
Save lucatironi/1339779 to your computer and use it in GitHub Desktop.
state_machine
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# GemFile | |
gem 'state_machine' | |
# offerta.rb | |
scope :nuove, Offerta.where(:stato => "nuova") | |
STATI = %w(nuova inviata accettata rifiutata scaduta annullata) | |
state_machine :stato, :initial => :nuova do | |
before_transition any => :inviata do |offerta, transition| | |
offerta.inviata_il = Time.zone.now | |
end | |
event :invia do | |
transition :nuova => :inviata | |
end | |
event :accetta do | |
transition [:nuova, :inviata] => :accettata | |
end | |
event :rifiuta do | |
transition [:nuova, :inviata] => :rifiutata | |
end | |
event :scadi do | |
transition [:nuova, :inviata] => :scaduta | |
end | |
event :annulla do | |
transition any => :annullata | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://github.com/pluginaweek/state_machine