Sha256: 8bd9fe4de3bb41813f9fca070b95e551837e3c5c1d286e0ca6c020342b11e24d

Contents?: true

Size: 890 Bytes

Versions: 17

Compression:

Stored size: 890 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

        self.class.clear_timeless_option
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 3 rubygems

Version Path
ish_lib_manager-0.0.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/mongoid-4.0.2/lib/mongoid/timestamps/created.rb
mongoid-5.0.0 lib/mongoid/timestamps/created.rb
mongoid-5.0.0.rc0 lib/mongoid/timestamps/created.rb
mongoid-5.0.0.beta lib/mongoid/timestamps/created.rb
mongoid-3.1.7 lib/mongoid/timestamps/created.rb
mongoid-4.0.2 lib/mongoid/timestamps/created.rb
mongoid-4.0.1 lib/mongoid/timestamps/created.rb
mongoid-4.0.0 lib/mongoid/timestamps/created.rb
mongoid-4.0.0.rc2 lib/mongoid/timestamps/created.rb
mongoid-4.0.0.rc1 lib/mongoid/timestamps/created.rb
mongoid-4.0.0.beta2 lib/mongoid/timestamps/created.rb
mongoid-4.0.0.beta1 lib/mongoid/timestamps/created.rb
mongoid-4.0.0.alpha2 lib/mongoid/timestamps/created.rb
mongoid-4.0.0.alpha1 lib/mongoid/timestamps/created.rb
mongoid-3.1.6 lib/mongoid/timestamps/created.rb
sepastian-mongoid-rails4-4.0.1.alpha lib/mongoid/timestamps/created.rb
sepastian-mongoid-rails4-4.0.0.alpha lib/mongoid/timestamps/created.rb