lib/couch_surfer/model.rb in addywaddy-couch_surfer-0.0.1 vs lib/couch_surfer/model.rb in addywaddy-couch_surfer-0.0.2
- old
+ new
@@ -141,17 +141,25 @@
def default
self.default_obj
end
# Automatically set <tt>updated_at</tt> and <tt>created_at</tt> fields
- # on the document whenever saving occurs. CouchRest uses a pretty
- # decent time format by default. See Time#to_json
+ # on the document whenever saving occurs. Save in a format parseable by Time
+ # and including milliseconds
+
def timestamps!
+ %w(updated_at created_at).each do |method|
+ define_method method do
+ Time.parse(@attributes[method])
+ end
+ end
before(:save) do
- self['updated_at'] = Time.now
+ time = Time.now
+ usec = time.usec
+ self['updated_at'] = time.strftime("%Y/%m/%d %H:%M:%S.#{time.usec} %z")
self['created_at'] = self['updated_at'] if new_document?
- end
+ end
end
# Name a method that will be called before the document is first saved,
# which returns a string to be used for the document's <tt>_id</tt>.
# Because CouchDB enforces a constraint that each id must be unique,
@@ -611,10 +619,10 @@
@attributes['couchrest-type'] = self.class.to_s
end
end
include ::Extlib::Hook
- register_instance_hooks :save, :create, :destroy
+ register_instance_hooks :save, :create, :update, :destroy
end
end
end
end
\ No newline at end of file