Sha256: 43565eedd78f25bb0e282042e2a585fd14bdfebf6058a8db67cdb13a8bfef949

Contents?: true

Size: 1.2 KB

Versions: 17

Compression:

Stored size: 1.2 KB

Contents

# encoding: utf-8
require "mongoid/timestamps/updated/short"

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

      included do
        include Mongoid::Timestamps::Timeless

        field :updated_at, type: Time
        set_callback :create, :before, :set_updated_at
        set_callback :update, :before, :set_updated_at
      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
        if able_to_set_updated_at?
          self.updated_at = Time.now.utc unless updated_at_changed?
        end

        self.class.clear_timeless_option
      end

      # Is the updated timestamp able to be set?
      #
      # @example Can the timestamp be set?
      #   document.able_to_set_updated_at?
      #
      # @return [ true, false ] If the timestamp can be set.
      #
      # @since 2.4.0
      def able_to_set_updated_at?
        !frozen? && !timeless? && (new_record? || changed?)
      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/updated.rb
mongoid-5.0.0 lib/mongoid/timestamps/updated.rb
mongoid-5.0.0.rc0 lib/mongoid/timestamps/updated.rb
mongoid-5.0.0.beta lib/mongoid/timestamps/updated.rb
mongoid-3.1.7 lib/mongoid/timestamps/updated.rb
mongoid-4.0.2 lib/mongoid/timestamps/updated.rb
mongoid-4.0.1 lib/mongoid/timestamps/updated.rb
mongoid-4.0.0 lib/mongoid/timestamps/updated.rb
mongoid-4.0.0.rc2 lib/mongoid/timestamps/updated.rb
mongoid-4.0.0.rc1 lib/mongoid/timestamps/updated.rb
mongoid-4.0.0.beta2 lib/mongoid/timestamps/updated.rb
mongoid-4.0.0.beta1 lib/mongoid/timestamps/updated.rb
mongoid-4.0.0.alpha2 lib/mongoid/timestamps/updated.rb
mongoid-4.0.0.alpha1 lib/mongoid/timestamps/updated.rb
mongoid-3.1.6 lib/mongoid/timestamps/updated.rb
sepastian-mongoid-rails4-4.0.1.alpha lib/mongoid/timestamps/updated.rb
sepastian-mongoid-rails4-4.0.0.alpha lib/mongoid/timestamps/updated.rb