1
0
Fork 0
mirror of https://github.com/aasm/aasm synced 2023-03-27 23:22:41 -04:00

Update Readme, add example of guards with param [ci skip]

This commit is contained in:
Anil Kumar Maurya 2017-07-27 13:49:20 +05:30 committed by GitHub
parent ed88361f5e
commit cc45d56773

View file

@ -282,11 +282,19 @@ class Cleaner
end
transitions :from => :idle, :to => :idle
end
event :clean_if_dirty do
transitions :from => :idle, :to => :cleaning, :guard => :if_dirty?
end
end
def cleaning_needed?
false
end
def if_dirty?(status)
status == :dirty
end
end
job = Cleaner.new
@ -294,6 +302,9 @@ job.may_clean? # => false
job.clean # => raises AASM::InvalidTransition
job.may_clean_if_needed? # => true
job.clean_if_needed! # idle
job.clean_if_dirty(:clean) # => false
job.clean_if_dirty(:dirty) # => true
```
You can even provide a number of guards, which all have to succeed to proceed