Sha256: 2f748490ccb5683c369ce9b46f368e402365650dab3a8696c8b3be2533dc99da

Contents?: true

Size: 476 Bytes

Versions: 11

Compression:

Stored size: 476 Bytes

Contents

module MongoMapper
  module Plugins
    module Timestamps
      module ClassMethods
        def timestamps!
          key :created_at, Time
          key :updated_at, Time
          class_eval { before_save :update_timestamps }
        end
      end
      
      module InstanceMethods
        def update_timestamps
          now = Time.now.utc
          self[:created_at] = now if new? && !created_at?
          self[:updated_at] = now
        end
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 4 rubygems

Version Path
mongo_mapper-0.7.5 lib/mongo_mapper/plugins/timestamps.rb
mongo_mapper_ign-0.7.4 lib/mongo_mapper/plugins/timestamps.rb
mongo_mapper-0.7.4 lib/mongo_mapper/plugins/timestamps.rb
mongo_mapper-0.7.3 lib/mongo_mapper/plugins/timestamps.rb
numon-0.0.1 lib/mongo_mapper/plugins/timestamps.rb
mongo_mapper-0.7.2 lib/mongo_mapper/plugins/timestamps.rb
mongo_mapper-0.7.1 lib/mongo_mapper/plugins/timestamps.rb
mongo_mapper-unstable-2010.3.8 lib/mongo_mapper/plugins/timestamps.rb
mongo_mapper-unstable-2010.3.5 lib/mongo_mapper/plugins/timestamps.rb
mongo_mapper-unstable-2010.3.4 lib/mongo_mapper/plugins/timestamps.rb
mongo_mapper-unstable-2010.3.3 lib/mongo_mapper/plugins/timestamps.rb