Sha256: f7e715e21d54a5c204853906fa941ce5e97d7ad54e661c0a1c979e351c0440ac

Contents?: true

Size: 788 Bytes

Versions: 22

Compression:

Stored size: 788 Bytes

Contents

# encoding: utf-8
module Mongoid #:nodoc:

  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

        unless methods.include? 'record_timestamps'
          class_attribute :record_timestamps
          self.record_timestamps = true
        end
      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
        self.created_at = Time.now.utc if !created_at
      end
    end
  end
end

Version data entries

22 entries across 22 versions & 2 rubygems

Version Path
mongoid-2.2.6 lib/mongoid/timestamps/created.rb
mongoid-2.2.5 lib/mongoid/timestamps/created.rb
mongoid-2.2.4 lib/mongoid/timestamps/created.rb
mongoid-2.2.3 lib/mongoid/timestamps/created.rb
mongoid-2.2.2 lib/mongoid/timestamps/created.rb
mongoid-2.2.1 lib/mongoid/timestamps/created.rb
mongoid-2.2.0 lib/mongoid/timestamps/created.rb
mongoid-2.1.9 lib/mongoid/timestamps/created.rb
mongoid-2.1.8 lib/mongoid/timestamps/created.rb
mongoid-2.1.7 lib/mongoid/timestamps/created.rb
mongoid-2.1.6 lib/mongoid/timestamps/created.rb
mongoid-2.1.5 lib/mongoid/timestamps/created.rb
mongoid-2.1.4 lib/mongoid/timestamps/created.rb
mongoid-2.1.3 lib/mongoid/timestamps/created.rb
mongoid-2.1.2 lib/mongoid/timestamps/created.rb
mongoid-2.1.1 lib/mongoid/timestamps/created.rb
mongoid-2.1.0 lib/mongoid/timestamps/created.rb
mongoid-braxton-2.0.2 lib/mongoid/timestamps/created.rb
mongoid-2.0.2 lib/mongoid/timestamps/created.rb
mongoid-2.0.1 lib/mongoid/timestamps/created.rb