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

* Add aasm features of ActiveRecord to Sequel! :) * All specs pass for sequel, activerecord, and mongoid. * Refactor Sequel models to be namespaced under “Sequel”. We should do something similar for ActiveRecord in the specs to avoid collisions. Addresses #474 (cherry picked from commit df97ce754f47864abbcb837227da5c4d0ff77289)
50 lines
1.2 KiB
Ruby
50 lines
1.2 KiB
Ruby
db = Sequel::DATABASES.first || Sequel.connect(SEQUEL_DB)
|
|
|
|
[:silent_persistors, :multiple_silent_persistors].each do |t|
|
|
db.create_table(t) do
|
|
primary_key :id
|
|
String "name"
|
|
String "status"
|
|
end
|
|
end
|
|
|
|
module Sequel
|
|
class SilentPersistor < Sequel::Model(:silent_persistors)
|
|
plugin :validation_helpers
|
|
|
|
include AASM
|
|
aasm :column => :status, :whiny_persistence => false do
|
|
state :sleeping, :initial => true
|
|
state :running
|
|
event :run do
|
|
transitions :to => :running, :from => :sleeping
|
|
end
|
|
event :sleep do
|
|
transitions :to => :sleeping, :from => :running
|
|
end
|
|
end
|
|
def validate
|
|
validates_presence :name
|
|
end
|
|
end
|
|
|
|
class MultipleSilentPersistor< Sequel::Model(:multiple_silent_persistors)
|
|
plugin :validation_helpers
|
|
|
|
include AASM
|
|
aasm :left, :column => :status, :whiny_persistence => false do
|
|
state :sleeping, :initial => true
|
|
state :running
|
|
event :run do
|
|
transitions :to => :running, :from => :sleeping
|
|
end
|
|
event :sleep do
|
|
transitions :to => :sleeping, :from => :running
|
|
end
|
|
end
|
|
|
|
def validate
|
|
validates_presence :name
|
|
end
|
|
end
|
|
end
|