Sha256: 563e250016c93e6815ef7de40bf43d1207ff92e8c515d1d69650d4b8308c9e4a

Contents?: true

Size: 532 Bytes

Versions: 5

Compression:

Stored size: 532 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

      module InstanceMethods
        def update_timestamps
          now = Time.now.utc
          self[:created_at] = now if !persisted? && !created_at?
          self[:updated_at] = now
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
mongo_mapper-0.10.1 lib/mongo_mapper/plugins/timestamps.rb
mongo_mapper-0.10.0 lib/mongo_mapper/plugins/timestamps.rb
mongo_mapper-0.9.2 lib/mongo_mapper/plugins/timestamps.rb
mongo_mapper-0.9.1 lib/mongo_mapper/plugins/timestamps.rb
mongo_mapper-0.9.0 lib/mongo_mapper/plugins/timestamps.rb