Sha256: 502fc2b86a75439ca965fdb3f683deb29f6eb3b5896b5e75aab7fd16a76c735c

Contents?: true

Size: 878 Bytes

Versions: 56

Compression:

Stored size: 878 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
        include Mongoid::Timestamps::Timeless

        field :created_at, type: Time
        set_callback :create, :before, :set_created_at
      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 !timeless? && !created_at
          time = Time.now.utc
          self.updated_at = time if is_a?(Updated) && !updated_at_changed?
          self.created_at = time
        end
        clear_timeless_option
      end
    end
  end
end

Version data entries

56 entries across 52 versions & 3 rubygems

Version Path
mongoid-7.0.13 lib/mongoid/timestamps/created.rb
mongoid-7.0.12 lib/mongoid/timestamps/created.rb
mongoid-6.4.8 lib/mongoid/timestamps/created.rb
mongoid-7.0.11 lib/mongoid/timestamps/created.rb
mongoid-7.0.10 lib/mongoid/timestamps/created.rb
mongoid-6.4.7 lib/mongoid/timestamps/created.rb
mongoid-6.4.5 lib/mongoid/timestamps/created.rb
mongoid-7.0.8 lib/mongoid/timestamps/created.rb
mongoid-7.0.7 lib/mongoid/timestamps/created.rb
mongoid-7.0.6 lib/mongoid/timestamps/created.rb
mongoid-5.4.1 lib/mongoid/timestamps/created.rb
mongoid-7.0.5 lib/mongoid/timestamps/created.rb
mongoid-7.0.4 lib/mongoid/timestamps/created.rb
mongoid-6.4.4 lib/mongoid/timestamps/created.rb
mongoid-7.0.3 lib/mongoid/timestamps/created.rb
mongoid-6.4.2 lib/mongoid/timestamps/created.rb
mongoid-7.0.2 lib/mongoid/timestamps/created.rb
mongoid-7.0.1 lib/mongoid/timestamps/created.rb
mongoid-6.4.1 lib/mongoid/timestamps/created.rb
mongoid-5.4.0 lib/mongoid/timestamps/created.rb