Skip to content

@cobbr2 /vehicle_enum.rb
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Can't get my state_machine to Enum erate
class VehicleEnum
include DataMapper::Resource
property :id, Serial
property :name, String
property :state, Enum[ :parked, :idling ]
state_machine :initial => :parked do
event :ignite do
transition :parked => :idling
end
state :idling do
validates_with_method :name_is_fred
end
end
def name_is_fred
return true if name == "fred"
return [false, "Only fred can be idling"]
end
end
fred = VehicleEnum.create({:name => 'fred'})
fred.ignite or raise "failed: couldn't ignite fred"
fred.clean? or raise "failed: couldn't save an idle fred"
wilma = VehicleEnum.create({:name => 'wilma'})
!wilma.ignite or raise "failed: could ignite wilma"
!wilma.errors.blank? or raise "failed: wilma has no errors"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.