123456789_123456789_123456789_123456789_123456789_

Module: Mongoid::Timestamps::Updated

Relationships & Source Files
Namespace Children
Modules:
Extension / Inclusion / Inheritance Descendants
Included In:
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
self, ActiveSupport::Concern
Defined in: lib/mongoid/timestamps/updated.rb,
lib/mongoid/timestamps/updated/short.rb

Overview

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

Instance Attribute Summary

Instance Method Summary

DSL Calls

included

[ GitHub ]


13
14
15
16
17
18
19
# File 'lib/mongoid/timestamps/updated.rb', line 13

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

Instance Attribute Details

#able_to_set_updated_at?true | false (readonly)

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.

[ GitHub ]

  
# File 'lib/mongoid/timestamps/updated.rb', line 40

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

Instance Method Details

#set_updated_at

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

Examples:

::Set the updated at time.

person.set_updated_at
[ GitHub ]

  
# File 'lib/mongoid/timestamps/updated.rb', line 26

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

  clear_timeless_option
end