diff options
author | Joshua Peek <josh@joshpeek.com> | 2009-08-04 11:03:57 -0500 |
---|---|---|
committer | Joshua Peek <josh@joshpeek.com> | 2009-08-04 11:03:57 -0500 |
commit | aad5a30bf25d8a3167afd685fc91c99f4f09cc57 (patch) | |
tree | f700750ee088e483537fa7ee992a109b834b1ddc /activerecord/test/models/traffic_light.rb | |
parent | 55d1d12c32a1b99f3f07d2346b49a63650ba2e9d (diff) | |
download | rails-aad5a30bf25d8a3167afd685fc91c99f4f09cc57.tar.gz rails-aad5a30bf25d8a3167afd685fc91c99f4f09cc57.tar.bz2 rails-aad5a30bf25d8a3167afd685fc91c99f4f09cc57.zip |
Add simple support for ActiveModel's StateMachine for ActiveRecord
Diffstat (limited to 'activerecord/test/models/traffic_light.rb')
-rw-r--r-- | activerecord/test/models/traffic_light.rb | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/activerecord/test/models/traffic_light.rb b/activerecord/test/models/traffic_light.rb new file mode 100644 index 0000000000..f8cfddbef9 --- /dev/null +++ b/activerecord/test/models/traffic_light.rb @@ -0,0 +1,27 @@ +class TrafficLight < ActiveRecord::Base + include ActiveRecord::StateMachine + + state_machine do + state :off + + state :red + state :green + state :yellow + + event :red_on do + transitions :to => :red, :from => [:yellow] + end + + event :green_on do + transitions :to => :green, :from => [:red] + end + + event :yellow_on do + transitions :to => :yellow, :from => [:green] + end + + event :reset do + transitions :to => :red, :from => [:off] + end + end +end |