From 313aae3e3dde57cc7028a3d42521684d90fb06ed Mon Sep 17 00:00:00 2001 From: Sho Fukamachi Date: Sun, 30 Nov 2008 12:36:24 +1100 Subject: [PATCH 1/2] modified Time#to_json monkeypatch to include microseconds --- lib/couchrest/monkeypatches.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/couchrest/monkeypatches.rb b/lib/couchrest/monkeypatches.rb index 58b8fe9..da676d7 100644 --- a/lib/couchrest/monkeypatches.rb +++ b/lib/couchrest/monkeypatches.rb @@ -8,7 +8,7 @@ class Time def to_json(options = nil) u = self.utc - %("#{u.strftime("%Y/%m/%d %H:%M:%S +0000")}") + %("#{u.strftime("%Y/%m/%d %H:%M:%S.#{u.usec} +0000")}") end # Decodes the JSON time format to a UTC time. From 0c527baa254cf617aa463e02b93e28dce29787b0 Mon Sep 17 00:00:00 2001 From: Sho Fukamachi Date: Sun, 30 Nov 2008 12:40:01 +1100 Subject: [PATCH 2/2] modified apply_defaults in CouchRest::Model to allow Procs in defaults and to safely clone (not reference) defaults from the class variable --- lib/couchrest/core/model.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/couchrest/core/model.rb b/lib/couchrest/core/model.rb index 0fccb27..9d38cb8 100644 --- a/lib/couchrest/core/model.rb +++ b/lib/couchrest/core/model.rb @@ -526,7 +526,11 @@ module CouchRest def apply_defaults if self.class.default self.class.default.each do |k,v| - self[k] = v + if v.class == Proc + self[k.to_s] = v.call + else + self[k.to_s] = Marshal.load(Marshal.dump(v)) + end end end end