Module: Mongoid::Timestamps::Updated

Extended by:
ActiveSupport::Concern
Included in:
Mongoid::Timestamps
Defined in:
build/mongoid-master/lib/mongoid/timestamps/updated.rb,
build/mongoid-master/lib/mongoid/timestamps/updated/short.rb

Overview

This module handles the behavior for setting up document updated at timestamp.

Defined Under Namespace

Modules: Short

Instance Method Summary collapse

Instance Method Details

#able_to_set_updated_at?true, false

Is the updated timestamp able to be set?

Examples:

Can the timestamp be set?

document.able_to_set_updated_at?

Returns:

  • (true, false)

    If the timestamp can be set.

Since:

  • 2.4.0



42
43
44
# File 'build/mongoid-master/lib/mongoid/timestamps/updated.rb', line 42

def able_to_set_updated_at?
  !frozen? && !timeless? && (new_record? || changed?)
end

#set_updated_atObject

Update the updated_at field on the Document to the current time. This is only called on create and on save.

Examples:

Set the updated at time.

person.set_updated_at


26
27
28
29
30
31
32
# File 'build/mongoid-master/lib/mongoid/timestamps/updated.rb', line 26

def set_updated_at
  if able_to_set_updated_at?
    self.updated_at = Time.now.utc unless updated_at_changed?
  end

  clear_timeless_option
end