Sha256: 1f233385e8c9e9ca6f35cbc6d354a98afebfd5f8bb6c692fd8c3e92942d02102

Contents?: true

Size: 908 Bytes

Versions: 27

Compression:

Stored size: 908 Bytes

Contents

# frozen_string_literal: true
# encoding: utf-8

require "mongoid/timestamps/created/short"

module Mongoid
  module Timestamps
    # This module handles the behavior 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

27 entries across 27 versions & 2 rubygems

Version Path
mongoid-7.3.5 lib/mongoid/timestamps/created.rb
mongoid-7.3.4 lib/mongoid/timestamps/created.rb
mongoid-7.1.11 lib/mongoid/timestamps/created.rb
mongoid-7.2.6 lib/mongoid/timestamps/created.rb
mongoid-7.3.3 lib/mongoid/timestamps/created.rb
mongoid-7.3.2 lib/mongoid/timestamps/created.rb
mongoid-7.2.5 lib/mongoid/timestamps/created.rb
mongoid-7.1.10 lib/mongoid/timestamps/created.rb
mongoid-7.1.9 lib/mongoid/timestamps/created.rb
mongoid-7.2.4 lib/mongoid/timestamps/created.rb
mongoid-7.3.1 lib/mongoid/timestamps/created.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/mongoid-7.1.7/lib/mongoid/timestamps/created.rb
mongoid-7.3.0 lib/mongoid/timestamps/created.rb
mongoid-7.2.3 lib/mongoid/timestamps/created.rb
mongoid-7.1.8 lib/mongoid/timestamps/created.rb
mongoid-7.2.2 lib/mongoid/timestamps/created.rb
mongoid-7.2.1 lib/mongoid/timestamps/created.rb
mongoid-7.1.7 lib/mongoid/timestamps/created.rb
mongoid-7.2.0 lib/mongoid/timestamps/created.rb
mongoid-7.1.6 lib/mongoid/timestamps/created.rb