Skip to content

Instantly share code, notes, and snippets.

@tpitale
Created July 6, 2009 01:06
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 tpitale/141206 to your computer and use it in GitHub Desktop.
Save tpitale/141206 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'dm-core'
DataMapper::Logger.new($stdout, :debug)
DataMapper.setup(:default, 'sqlite3::memory:')
class Session
include DataMapper::Resource
property :id, Serial
property :data, Object, :lazy => false
end
DataMapper.auto_migrate!
SessionHash = Class.new(Hash)
session_data = SessionHash.new
session = Session.create(:data => session_data)
# Simply assign data to the object
session.data["flash"] = {:error => "I'm not dirty!"}
puts session.dirty? # would love to be true, but not required
# Reassign an edited object
session_data["flash"] = {:error => "I'm not dirty!"}
session.data = session_data
puts session.dirty? # why not dirty?!
# Reassign a dupped object
session.data = session_data.dup
puts session.dirty? # not even trying, are we?
# Clear, and reassign
session.data = nil
session.data = session_data
puts session.dirty? # well, that sux
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment