Created
January 14, 2010 21:55
-
-
Save schof/277545 to your computer and use it in GitHub Desktop.
This file contains 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
Shipment.class_eval do | |
def editable_by?(user) | |
%w(pending ready_to_ship unable_to_ship needs_fulfilment).include?(state) or user.has_role?(:admin) | |
end | |
Shipment.state_machines[:state] = StateMachine::Machine.new(Shipment, :initial => 'pending') do | |
event :ready do | |
transition :from => 'pending', :to => 'ready_to_ship' | |
end | |
event :pend do | |
transition :from => 'ready_to_ship', :to => 'pending' | |
end | |
event :ship do | |
transition :from => ['needs_fulfilment', 'acknowledged'], :to => 'shipped' | |
end | |
event :transmit do | |
transition :from => 'ready_to_ship', :to => 'transmitted' | |
end | |
event :acknowledge do | |
transition :from => 'transmitted', :to => 'acknowledged' | |
end | |
event :flag do | |
transition :from => 'ready_to_ship', :to => 'needs_fulfilment' | |
end | |
event :problem do | |
transition :from => ['transmitted', 'acknowledged', 'needs_fulfilment'], :to => 'unable_to_ship' | |
end | |
after_transition :to => 'shipped', :do => :transition_order | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment