Sha256: a66c96a19d1274f78fcfc510367c1001afa9412248605b9af11d764bc8b1777b

Contents?: true

Size: 897 Bytes

Versions: 17

Compression:

Stored size: 897 Bytes

Contents

# frozen_string_literal: true

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.configured.now
          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

17 entries across 17 versions & 1 rubygems

Version Path
mongoid-8.1.8 lib/mongoid/timestamps/created.rb
mongoid-8.1.7 lib/mongoid/timestamps/created.rb
mongoid-8.1.6 lib/mongoid/timestamps/created.rb
mongoid-8.0.8 lib/mongoid/timestamps/created.rb
mongoid-8.1.5 lib/mongoid/timestamps/created.rb
mongoid-8.1.4 lib/mongoid/timestamps/created.rb
mongoid-8.0.7 lib/mongoid/timestamps/created.rb
mongoid-8.1.3 lib/mongoid/timestamps/created.rb
mongoid-8.1.2 lib/mongoid/timestamps/created.rb
mongoid-8.0.6 lib/mongoid/timestamps/created.rb
mongoid-8.1.1 lib/mongoid/timestamps/created.rb
mongoid-8.0.5 lib/mongoid/timestamps/created.rb
mongoid-8.1.0 lib/mongoid/timestamps/created.rb
mongoid-8.0.4 lib/mongoid/timestamps/created.rb
mongoid-8.0.3 lib/mongoid/timestamps/created.rb
mongoid-8.0.2 lib/mongoid/timestamps/created.rb
mongoid-8.0.1 lib/mongoid/timestamps/created.rb