2012-01-16 11:27:15 -05:00
|
|
|
require 'active_record'
|
|
|
|
|
|
|
|
class Validator < ActiveRecord::Base
|
2014-03-17 16:58:44 -04:00
|
|
|
|
2012-01-16 11:27:15 -05:00
|
|
|
include AASM
|
|
|
|
aasm :column => :status do
|
|
|
|
state :sleeping, :initial => true
|
2014-03-17 16:58:44 -04:00
|
|
|
state :running
|
|
|
|
state :failed, :after_enter => :fail
|
|
|
|
|
|
|
|
event :run, :after_commit => :change_name! do
|
2012-01-16 11:27:15 -05:00
|
|
|
transitions :to => :running, :from => :sleeping
|
|
|
|
end
|
|
|
|
event :sleep do
|
|
|
|
transitions :to => :sleeping, :from => :running
|
|
|
|
end
|
2013-10-22 06:30:04 -04:00
|
|
|
event :fail do
|
|
|
|
transitions :to => :failed, :from => [:sleeping, :running]
|
|
|
|
end
|
2012-01-16 11:27:15 -05:00
|
|
|
end
|
2014-03-17 16:58:44 -04:00
|
|
|
|
2012-01-16 11:27:15 -05:00
|
|
|
validates_presence_of :name
|
2013-10-22 06:30:04 -04:00
|
|
|
|
|
|
|
def change_name!
|
|
|
|
self.name = "name changed"
|
|
|
|
save!
|
|
|
|
end
|
|
|
|
|
|
|
|
def fail
|
|
|
|
raise StandardError.new('failed on purpose')
|
|
|
|
end
|
2012-01-16 11:27:15 -05:00
|
|
|
end
|