I'm trying to work on a finite state machine with AASM in Ruby. This is a part of my code:
event :Orthography, :before => :to_lowercase do
puts "Check Orthography"
transitions :from => :Initialized, :to => :UniquenessChecked
end
event :Uniqueness do
puts "Check Uniqueness"
transitions :from => :UniquenessChecked, :to => :OrthographyChecked
end
...
def to_lowercase
puts "To lowercase test"
end
I get as puts log:
Check Orthography
Check Uniqueness
To lowercase test
But I expect, because I use the before callback:
To lowercase test
Check Orthography
Check Uniqueness
How can I do something before or on enter of a event?
Your to_lowercase
method is called before the event.
I guess you are confused by the Check Orthography
and Check Uniqueness
outputs that happen before the To lowercase test
. This happens because the first two puts
are defined on class level and are printed when the file is read and the state machine is configured.
Whereas the last puts
is called in a method, when the instance is already created and a event is fired.
You can test that by defining the state machine, but not firing any events: You will still see the output from the state machine definition.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.