Sha256: 21cdc329ece41fa89496f02e357746de5f73e2b30c0f65c0d5d4f0d01b155b2b

Contents?: true

Size: 763 Bytes

Versions: 23

Compression:

Stored size: 763 Bytes

Contents

# encoding: utf-8
module Mongoid
  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, if: :timestamping?
      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 !created_at
          time = Time.now.utc
          self.updated_at = time if is_a?(Updated) && !updated_at_changed?
          self.created_at = time
        end
      end
    end
  end
end

Version data entries

23 entries across 23 versions & 2 rubygems

Version Path
mongoid-3.0.23 lib/mongoid/timestamps/created.rb
mongoid-3.0.22 lib/mongoid/timestamps/created.rb
mongoid-3.0.21 lib/mongoid/timestamps/created.rb
mongoid-3.0.20 lib/mongoid/timestamps/created.rb
mongoid-3.0.19 lib/mongoid/timestamps/created.rb
mongoid-3.0.18 lib/mongoid/timestamps/created.rb
mongoid-3.0.17 lib/mongoid/timestamps/created.rb
sunrise-cms-0.5.0.rc1 vendor/bundle/ruby/1.9.1/gems/mongoid-3.0.16/lib/mongoid/timestamps/created.rb
mongoid-3.0.16 lib/mongoid/timestamps/created.rb
mongoid-3.0.15 lib/mongoid/timestamps/created.rb
mongoid-3.0.14 lib/mongoid/timestamps/created.rb
mongoid-3.0.13 lib/mongoid/timestamps/created.rb
mongoid-3.0.12 lib/mongoid/timestamps/created.rb
mongoid-3.0.11 lib/mongoid/timestamps/created.rb
mongoid-3.0.10 lib/mongoid/timestamps/created.rb
mongoid-3.0.9 lib/mongoid/timestamps/created.rb
mongoid-3.0.6 lib/mongoid/timestamps/created.rb
mongoid-3.0.5 lib/mongoid/timestamps/created.rb
mongoid-3.0.4 lib/mongoid/timestamps/created.rb
mongoid-3.0.3 lib/mongoid/timestamps/created.rb