Module: Mongoid::Timestamps::Timeless::ClassMethods
- Defined in:
- lib/mongoid/timestamps/timeless.rb
Instance Method Summary collapse
-
#clear_timeless_option ⇒ true
Removes the timeless option on the current class.
-
#clear_timeless_option_on_update ⇒ true
Sets to remove the timeless option when the next instance of the current class is updated.
-
#set_timeless_counter(counter) ⇒ Integer | nil
Clears the timeless counter for the current class if the value has reached zero.
-
#timeless(&block) ⇒ Object | Class
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 current class should skip timestamping.
Instance Method Details
#clear_timeless_option ⇒ true
Removes the timeless option on the current class.
153 154 155 156 157 158 159 |
# File 'lib/mongoid/timestamps/timeless.rb', line 153 def clear_timeless_option if counter = Timeless[name] counter -= 1 set_timeless_counter(counter) end true end |
#clear_timeless_option_on_update ⇒ true
Sets to remove the timeless option when the next instance of the current class is updated.
165 166 167 168 169 170 171 |
# File 'lib/mongoid/timestamps/timeless.rb', line 165 def clear_timeless_option_on_update return unless counter = Timeless[name] counter -= 1 if self < Mongoid::Timestamps::Created counter -= 1 if self < Mongoid::Timestamps::Updated set_timeless_counter(counter) end |
#set_timeless_counter(counter) ⇒ Integer | nil
Clears the timeless counter for the current class if the value has reached zero.
180 181 182 |
# File 'lib/mongoid/timestamps/timeless.rb', line 180 def set_timeless_counter(counter) Timeless[name] = (counter == 0) ? nil : counter end |
#timeless(&block) ⇒ Object | Class
Skip timestamping for the duration of the given block, or (in the deprecated, block-less form) for the next persistence operation.
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
# File 'lib/mongoid/timestamps/timeless.rb', line 128 def timeless(&block) return Timeless.with_timeless(&block) if block locations = caller_locations # if this is called from the #timeless instance method, look up one # level higher for the call site locations.shift if locations[0].path == __FILE__ Mongoid.deprecation_warning( :timeless_sans_block, 'Calling #timeless without a block is deprecated; pass a block ' \ 'instead, e.g. `record.timeless { record.save }`.', locations ) counter = 0 counter += 1 if self < Mongoid::Timestamps::Created counter += 1 if self < Mongoid::Timestamps::Updated Timeless[name] = counter self end |
#timeless? ⇒ true | false
Returns whether the current class should skip timestamping. This is true when either a block-based timeless scope is active on the current thread/fiber, or the deprecated per-class counter is set.
190 191 192 |
# File 'lib/mongoid/timestamps/timeless.rb', line 190 def timeless? Timeless. || !!Timeless[name] end |