Module: Mongoid::Timestamps::Timeless
| Relationships & Source Files | |
| Namespace Children | |
|
Modules:
| |
| Super Chains via Extension / Inclusion / Inheritance | |
|
Class Chain:
self,
Forwardable,
ActiveSupport::Concern
|
|
| Defined in: | lib/mongoid/timestamps/timeless.rb |
Overview
This module adds behavior for turning off timestamping in single or multiple calls.
Constant Summary
-
TIMELESS_FLAG_KEY =
# File 'lib/mongoid/timestamps/timeless.rb', line 58
The key to use to store the block-based timeless flag.
'[mongoid]:timeless-flag' -
TIMELESS_TABLE_KEY =
# File 'lib/mongoid/timestamps/timeless.rb', line 55
The key to use to store the timeless table
'[mongoid]:timeless'
Class Attribute Summary
-
.suppressing_timestamps? ⇒ true | false
readonly
Internal use only
Whether a block-based timeless scope is currently active on this thread/fiber.
Class Method Summary
-
.set_suppressing_timestamps(value)
Internal use only
::Setwhether a block-based timeless scope is active on this thread/fiber. -
.timeless_table ⇒ Hash
Internal use only
Returns the in-memory thread cache of classes for which to skip timestamping.
-
.with_timeless ⇒ Object
Skip timestamping for the duration of the given block, on the current thread or fiber.
Instance Attribute Summary
-
#timeless? ⇒ true | false
readonly
Returns whether the document should skip timestamping.
Instance Method Summary
-
#clear_timeless_option ⇒ true
Clears out the timeless option.
-
#timeless(&block) ⇒ Object | Document
readonly
Skip timestamping for the duration of the given block, or (in the deprecated, block-less form) for the next persistence operation.
Class Attribute Details
.suppressing_timestamps? ⇒ true | false (readonly)
Whether a block-based timeless scope is currently active on this thread/fiber.
# File 'lib/mongoid/timestamps/timeless.rb', line 101
def !!Threaded.get(TIMELESS_FLAG_KEY) { false } end
Class Method Details
.set_suppressing_timestamps(value)
::Set whether a block-based timeless scope is active on this
thread/fiber.
# File 'lib/mongoid/timestamps/timeless.rb', line 111
def (value) Threaded.set(TIMELESS_FLAG_KEY, value) end
.timeless_table ⇒ Hash
Returns the in-memory thread cache of classes for which to skip timestamping.
# File 'lib/mongoid/timestamps/timeless.rb', line 66
def timeless_table Threaded.get(TIMELESS_TABLE_KEY) { {} } end
.with_timeless ⇒ Object
Skip timestamping for the duration of the given block, on the current thread or fiber. This applies to every document persisted while the block is executing, regardless of class, including cascaded embedded children at any nesting depth.
# File 'lib/mongoid/timestamps/timeless.rb', line 83
def with_timeless # Only the outermost block owns the flag: if we are already inside a # timeless scope, we leave the suppression in place when this block # ends. This avoids tracking a nesting depth that could drift out of # sync. already_timeless = (true) unless already_timeless yield ensure (false) unless already_timeless end
Instance Attribute Details
#timeless? ⇒ true | false (readonly)
Returns whether the document should skip timestamping.
# File 'lib/mongoid/timestamps/timeless.rb', line 47
def timeless? self.class.timeless? end
Instance Method Details
#clear_timeless_option ⇒ true
Clears out the timeless option.
# File 'lib/mongoid/timestamps/timeless.rb', line 16
def clear_timeless_option if persisted? self.class.clear_timeless_option_on_update else self.class.clear_timeless_option end true end
#timeless(&block) ⇒ Object | Document (readonly)
Skip timestamping for the duration of the given block, or (in the deprecated, block-less form) for the next persistence operation.
# File 'lib/mongoid/timestamps/timeless.rb', line 36
def timeless(&block) return Timeless.with_timeless(&block) if block self.class.timeless self end