Module: Mongoid::Timestamps::Timeless
- Extended by:
- ActiveSupport::Concern, Forwardable
- Defined in:
- lib/mongoid/timestamps/timeless.rb
Overview
This module adds behavior for turning off timestamping in single or multiple calls.
Defined Under Namespace
Modules: ClassMethods
Constant Summary collapse
- TIMELESS_TABLE_KEY =
The key to use to store the timeless table
'[mongoid]:timeless'- TIMELESS_FLAG_KEY =
The key to use to store the block-based timeless flag.
'[mongoid]:timeless-flag'
Class Method Summary collapse
-
.set_suppressing_timestamps(value) ⇒ Object
private
Set whether a block-based timeless scope is active on this thread/fiber.
-
.suppressing_timestamps? ⇒ true | false
private
Whether a block-based timeless scope is currently active on this thread/fiber.
-
.timeless_table ⇒ Hash
private
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 Method Summary collapse
-
#clear_timeless_option ⇒ true
Clears out the timeless option.
-
#timeless(&block) ⇒ Object | Document
Skip timestamping for the duration of the given block, or (in the deprecated, block-less form) for the next persistence operation.
-
#timeless? ⇒ true | false
Returns whether the document should skip timestamping.
Class Method Details
.set_suppressing_timestamps(value) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Set whether a block-based timeless scope is active on this thread/fiber.
111 112 113 |
# File 'lib/mongoid/timestamps/timeless.rb', line 111 def (value) Threaded.set(TIMELESS_FLAG_KEY, value) end |
.suppressing_timestamps? ⇒ true | false
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Whether a block-based timeless scope is currently active on this thread/fiber.
101 102 103 |
# File 'lib/mongoid/timestamps/timeless.rb', line 101 def !!Threaded.get(TIMELESS_FLAG_KEY) { false } end |
.timeless_table ⇒ Hash
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns the in-memory thread cache of classes for which to skip timestamping.
66 67 68 |
# 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.
83 84 85 86 87 88 89 90 91 92 93 |
# 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 Method Details
#clear_timeless_option ⇒ true
Clears out the timeless option.
16 17 18 19 20 21 22 23 |
# 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
Skip timestamping for the duration of the given block, or (in the deprecated, block-less form) for the next persistence operation.
36 37 38 39 40 41 |
# File 'lib/mongoid/timestamps/timeless.rb', line 36 def timeless(&block) return Timeless.with_timeless(&block) if block self.class.timeless self end |
#timeless? ⇒ true | false
Returns whether the document should skip timestamping.
47 48 49 |
# File 'lib/mongoid/timestamps/timeless.rb', line 47 def timeless? self.class.timeless? end |