Sha256: 6044bc49c4c504f5a046203de5e4f4ef49760e327499f56baa9c36bbca880734

Contents?: true

Size: 483 Bytes

Versions: 6

Compression:

Stored size: 483 Bytes

Contents

# encoding: UTF-8
module MongoMapper
  module Plugins
    module Timestamps
      extend ActiveSupport::Concern

      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
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 3 rubygems

Version Path
mongo_mapper-0.12.0 lib/mongo_mapper/plugins/timestamps.rb
lookout-mongo_mapper-0.11.3 lib/mongo_mapper/plugins/timestamps.rb
mongo_mapper-0.11.2 lib/mongo_mapper/plugins/timestamps.rb
jamieorc-mongo_mapper-0.11.1.1 lib/mongo_mapper/plugins/timestamps.rb
mongo_mapper-0.11.1 lib/mongo_mapper/plugins/timestamps.rb
mongo_mapper-0.11.0 lib/mongo_mapper/plugins/timestamps.rb