Sha256: bc601db90dafa40816f70ace8d78b1bf1d63dbd08eaf93c1e394400eb9885795

Contents?: true

Size: 807 Bytes

Versions: 6

Compression:

Stored size: 807 Bytes

Contents

# encoding: utf-8
require "mongoid/timestamps/created/short"

module Mongoid
  module Timestamps
    # This module handles the behaviour for setting up document created at
    # timestamp.
    module Created
      extend ActiveSupport::Concern

      included do
        field :created_at, type: Time
        set_callback :create, :before, :set_created_at, if: :timestamping?
      end

      # Update the created_at field on the Document to the current time. This is
      # only called on create.
      #
      # @example Set the created at time.
      #   person.set_created_at
      def set_created_at
        if !created_at
          time = Time.now.utc
          self.updated_at = time if is_a?(Updated) && !updated_at_changed?
          self.created_at = time
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
mongoid-3.1.5 lib/mongoid/timestamps/created.rb
mongoid-3.1.4 lib/mongoid/timestamps/created.rb
mongoid-3.1.3 lib/mongoid/timestamps/created.rb
mongoid-3.1.2 lib/mongoid/timestamps/created.rb
mongoid-3.1.1 lib/mongoid/timestamps/created.rb
mongoid-3.1.0 lib/mongoid/timestamps/created.rb