Skip to content

Instantly share code, notes, and snippets.

@prathe
Created January 17, 2012 21:50
Show Gist options
  • Save prathe/1629153 to your computer and use it in GitHub Desktop.
Save prathe/1629153 to your computer and use it in GitHub Desktop.
state_machine :state, initial: :opened do
state :opened
state :confirmed
state :rejected
state :closed
event :confirm_it do
# only user
transition [:opened, :rejected] => :confirmed
end
event :unconfirm_it do
# only user
transition :confirmed => :opened
end
event :reject_it do
# only admin
transition [:opened, :confirmed] => :rejected
end
event :close_it do
# only admin
transition [:opened, :confirmed, :rejected] => :closed
end
after_transition :to => [:confirmed], :do => :set_confirmed
after_transition :to => [:rejected], :do => :increment_rejected_count
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment