Sha256: 6b2cad65900889a93d39b254b93eda5139633e795cec23fd3f1890ea35c2a717

Contents?: true

Size: 688 Bytes

Versions: 8

Compression:

Stored size: 688 Bytes

Contents

# encoding: utf-8
module Mongoid
  module Timestamps
    extend ActiveSupport::Concern
    included do
      field :created_at, :type => Time
      field :updated_at, :type => Time
      before_save :set_created_at, :set_updated_at
    end

    module InstanceMethods

      # Update the created_at field on the Document to the current time. This is
      # only called on create.
      def set_created_at
        self.created_at = Time.now.utc if !created_at
      end

      # Update the updated_at field on the Document to the current time.
      # This is only called on create and on save.
      def set_updated_at
        self.updated_at = Time.now.utc
      end
    end

  end
end

Version data entries

8 entries across 8 versions & 4 rubygems

Version Path
mongoid-1.9.5 lib/mongoid/timestamps.rb
mongoid-with-auth-1.9.4 lib/mongoid/timestamps.rb
mongoid-rails2-1.9.4 lib/mongoid/timestamps.rb
mongoid-rails2-1.9.3 lib/mongoid/timestamps.rb
mongoid-1.9.2 lib/mongoid/timestamps.rb
sskirby-mongoid-1.9.1 lib/mongoid/timestamps.rb
mongoid-1.9.1 lib/mongoid/timestamps.rb
mongoid-1.9.0 lib/mongoid/timestamps.rb