lib/mongo_mapper/plugins/timestamps.rb in mongo_mapper-0.12.0 vs lib/mongo_mapper/plugins/timestamps.rb in mongo_mapper-0.13.0.beta1

- old
+ new

@@ -2,21 +2,28 @@ module MongoMapper module Plugins module Timestamps extend ActiveSupport::Concern + included do + class_attribute :record_timestamps + self.record_timestamps = true + end + module ClassMethods def timestamps! key :created_at, Time key :updated_at, Time class_eval { before_save :update_timestamps } end end def update_timestamps - now = Time.now.utc - self[:created_at] = now if !persisted? && !created_at? - self[:updated_at] = now + if self.record_timestamps + now = Time.now.utc + self[:created_at] = now if !persisted? && !created_at? + self[:updated_at] = now + end end end end -end \ No newline at end of file +end