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 ⇒ Class
Begin an execution that should skip timestamping.
-
#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.
86 87 88 89 90 91 92 |
# File 'lib/mongoid/timestamps/timeless.rb', line 86 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.
98 99 100 101 102 103 104 |
# File 'lib/mongoid/timestamps/timeless.rb', line 98 def clear_timeless_option_on_update if counter = Timeless[name] counter -= 1 if self < Mongoid::Timestamps::Created counter -= 1 if self < Mongoid::Timestamps::Updated set_timeless_counter(counter) end end |
#set_timeless_counter(counter) ⇒ Integer | nil
Clears the timeless counter for the current class if the value has reached zero.
113 114 115 |
# File 'lib/mongoid/timestamps/timeless.rb', line 113 def set_timeless_counter(counter) Timeless[name] = (counter == 0) ? nil : counter end |
#timeless ⇒ Class
Begin an execution that should skip timestamping.
75 76 77 78 79 80 81 |
# File 'lib/mongoid/timestamps/timeless.rb', line 75 def timeless 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.
121 122 123 |
# File 'lib/mongoid/timestamps/timeless.rb', line 121 def timeless? !!Timeless[name] end |