Created
July 6, 2009 01:06
-
-
Save tpitale/141206 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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