Skip to content

Instantly share code, notes, and snippets.

@lsimoneau
Created February 28, 2012 05:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lsimoneau/1929985 to your computer and use it in GitHub Desktop.
Save lsimoneau/1929985 to your computer and use it in GitHub Desktop.
DataMapper / State_Machine save hook issue
require 'dm-core'
require 'state_machine'
class Vehicle
include DataMapper::Resource
state_machine :initial => :parked do
event :ignite do
transition :parked => :idling
end
end
after :save do
ignite
end
end
DataMapper.setup(:default, :adapter => :in_memory)
v = Vehicle.new
v.save
p "State after saving is #{v.state}"
v.save
p "State after saving again is #{v.state}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment