Sha256: 13c616f361f523fbb640a00f030f9de0b7fc4873803e25d87d80c52fdbe8892b

Contents?: true

Size: 740 Bytes

Versions: 53

Compression:

Stored size: 740 Bytes

Contents

# encoding: utf-8
module Mongoid
  module Timestamps

    def self.included(base)
      base.class_eval do
        include InstanceMethods
        field :created_at, :type => Time
        field :updated_at, :type => Time
        before_save :set_created_at, :set_updated_at
      end
    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

53 entries across 53 versions & 1 rubygems

Version Path
mongoid-1.2.14 lib/mongoid/timestamps.rb
mongoid-1.2.13 lib/mongoid/timestamps.rb
mongoid-1.2.12 lib/mongoid/timestamps.rb
mongoid-1.2.11 lib/mongoid/timestamps.rb
mongoid-1.2.10 lib/mongoid/timestamps.rb
mongoid-1.2.9 lib/mongoid/timestamps.rb
mongoid-1.2.8 lib/mongoid/timestamps.rb
mongoid-1.2.7 lib/mongoid/timestamps.rb
mongoid-1.2.6 lib/mongoid/timestamps.rb
mongoid-1.2.5 lib/mongoid/timestamps.rb
mongoid-1.2.4 lib/mongoid/timestamps.rb
mongoid-1.2.3 lib/mongoid/timestamps.rb
mongoid-1.2.2 lib/mongoid/timestamps.rb
mongoid-1.2.1 lib/mongoid/timestamps.rb
mongoid-1.2.0 lib/mongoid/timestamps.rb
mongoid-1.1.4 lib/mongoid/timestamps.rb
mongoid-1.1.3 lib/mongoid/timestamps.rb
mongoid-1.1.2 lib/mongoid/timestamps.rb
mongoid-1.1.1 lib/mongoid/timestamps.rb
mongoid-1.1.0 lib/mongoid/timestamps.rb