Module: Mongoid::Timestamps::Created
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/created.rb, lib/mongoid/timestamps/created/short.rb |
Overview
This module handles the behavior for setting up document created at timestamp.
Instance Attribute Summary
-
#able_to_set_created_at? ⇒ true, false
readonly
Is the created timestamp able to be set?
Instance Method Summary
-
#set_created_at
Update the created_at field on the
::Mongoid::Document
to the current time.
DSL Calls
included
[ GitHub ]13 14 15 16 17 18
# File 'lib/mongoid/timestamps/created.rb', line 13
included do include Mongoid::Timestamps::Timeless field :created_at, type: Time set_callback :create, :before, :set_created_at end
Instance Attribute Details
#able_to_set_created_at? ⇒ true
, false
(readonly)
Is the created timestamp able to be set?
# File 'lib/mongoid/timestamps/created.rb', line 37
def able_to_set_created_at? !frozen? && !timeless? && !created_at end
Instance Method Details
#set_created_at
Update the created_at field on the ::Mongoid::Document
to the current time. This is only called on create.
# File 'lib/mongoid/timestamps/created.rb', line 25
def set_created_at if able_to_set_created_at? now = Time.current self.updated_at = now if is_a?(Updated) && !updated_at_changed? self.created_at = now end clear_timeless_option end