Sha256: 89bb9e7cfdb52d2b235d10cb901c065a49ae5867ae8080f0a0e357ee68925ff5

Contents?: true

Size: 741 Bytes

Versions: 35

Compression:

Stored size: 741 Bytes

Contents

module Mongoid
  module Timestamps

    def self.included(base)
      base.class_eval do
        include InstanceMethods
        field :created_at, :type => Time
        field :modified_at, :type => Time
        before_save :update_created_at, :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.utc if !created_at
      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.utc
      end
    end

  end
end

Version data entries

35 entries across 35 versions & 1 rubygems

Version Path
mongoid-0.9.4 lib/mongoid/timestamps.rb
mongoid-0.9.3 lib/mongoid/timestamps.rb
mongoid-0.9.2 lib/mongoid/timestamps.rb
mongoid-0.9.1 lib/mongoid/timestamps.rb
mongoid-0.9.0 lib/mongoid/timestamps.rb
mongoid-0.8.10 lib/mongoid/timestamps.rb
mongoid-0.8.9 lib/mongoid/timestamps.rb
mongoid-0.8.8 lib/mongoid/timestamps.rb
mongoid-0.8.7 lib/mongoid/timestamps.rb
mongoid-0.8.6 lib/mongoid/timestamps.rb
mongoid-0.8.5 lib/mongoid/timestamps.rb
mongoid-0.8.4 lib/mongoid/timestamps.rb
mongoid-0.8.3 lib/mongoid/timestamps.rb
mongoid-0.8.2 lib/mongoid/timestamps.rb
mongoid-0.8.1 lib/mongoid/timestamps.rb
mongoid-0.7.10 lib/mongoid/timestamps.rb
mongoid-0.7.9 lib/mongoid/timestamps.rb
mongoid-0.7.8 lib/mongoid/timestamps.rb
mongoid-0.7.7 lib/mongoid/timestamps.rb
mongoid-0.7.6 lib/mongoid/timestamps.rb