Sha256: 2801230c9e2c0aeadf53219fdcc7715ca80bd20042d4ecd475a90cabf30fea26

Contents?: true

Size: 646 Bytes

Versions: 4

Compression:

Stored size: 646 Bytes

Contents

# encoding: UTF-8
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
        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

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
mongo_mapper-0.13.1 lib/mongo_mapper/plugins/timestamps.rb
mongo_mapper-0.13.0 lib/mongo_mapper/plugins/timestamps.rb
mongo_mapper-0.13.0.beta2 lib/mongo_mapper/plugins/timestamps.rb
mongo_mapper-0.13.0.beta1 lib/mongo_mapper/plugins/timestamps.rb