Sha256: fb0cf139c9be2c5ca2460218099e0e4f1318a9b72222292854eed4d8784a239d

Contents?: true

Size: 892 Bytes

Versions: 17

Compression:

Stored size: 892 Bytes

Contents

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

  module Timestamps
    # This module handles the behaviour for setting up document updated at
    # timestamp.
    module Updated
      extend ActiveSupport::Concern

      included do
        field :updated_at, :type => Time

        set_callback :save, :before, :set_updated_at, :if => Proc.new { |doc|
          doc.new_record? || doc.changed?
        }

        unless methods.include? 'record_timestamps'
          class_attribute :record_timestamps
          self.record_timestamps = true
        end
      end

      # Update the updated_at field on the Document to the current time.
      # This is only called on create and on save.
      #
      # @example Set the updated at time.
      #   person.set_updated_at
      def set_updated_at
        self.updated_at = Time.now.utc unless self.updated_at_changed?
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

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