Created
August 28, 2012 09:30
-
-
Save svs/3496546 to your computer and use it in GitHub Desktop.
AWSM - After Workflow 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
class Document | |
# .... | |
# ..snip... | |
# .... | |
workflow do | |
state :created do | |
event :scan, :transitions_to => :scanned, :if => Proc.new{|t| !(t.scans.empty?)} | |
event :to_edit, :transitions_to => :editing | |
end | |
state :scanned do | |
event :to_edit, :transitions_to => :editing | |
end | |
state :editing do | |
# snip | |
end | |
state :completed do | |
# snip | |
end | |
state :incomplete do | |
# snip | |
end | |
state :illegible do | |
# snip | |
end | |
state :checker_rejected do | |
# snip | |
end | |
state :checker_accepted do | |
# snip | |
end | |
state :user_rejected do | |
# snip | |
end | |
state :user_accepted do | |
# snip | |
end | |
on_transition do |from, to, event, *event_args| | |
# put all access control validations here | |
# *args is basically current_user | |
halt! "not authorized" unless Ability.new(event_args[0]).can?(event, self) # sweet - all validations work through this one line. | |
AuditTrail.create(:from => from, :to => to, :event => event, :user => event_args[0], :model_name => self.class.to_s, :model_id => self.id) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment