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:
parent
ed88361f5e
commit
cc45d56773
1 changed files with 11 additions and 0 deletions
11
README.md
11
README.md
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue