Sha256: be8eae9495bd19ee1ac71ea82cced143114df1a28ab23deb2b44d650565eead8

Contents?: true

Size: 730 Bytes

Versions: 2

Compression:

Stored size: 730 Bytes

Contents

module Mongoid
  module Timestamps

    def self.included(base)
      base.class_eval do
        include InstanceMethods
        field :created_at
        field :modified_at
        before_create :update_created_at, :update_modified_at
        before_save :update_modified_at
      end
    end

    module InstanceMethods

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

      # Update the last_modified field on the Document to the current time.
      # This is only called on create and on save.
      def update_modified_at
        self.modified_at = Time.now
      end
    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
mongoid-0.4.8 lib/mongoid/timestamps.rb
mongoid-0.4.7 lib/mongoid/timestamps.rb