module Mongoid::Timestamps::Timeless::ClassMethods

Public Instance Methods

clear_timeless_option() click to toggle source

Removes the timeless option on the current class.

@return [ true ] Always true.

# 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() click to toggle source

Sets to remove the timeless option when the next instance of the current class is updated.

@return [ true ] Always true.

# 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) click to toggle source

Clears the timeless counter for the current class if the value has reached zero.

@param [ Integer ] counter The counter value.

@return [ Integer | nil ] The counter value, or nil

if the counter was cleared.
# File lib/mongoid/timestamps/timeless.rb, line 113
def set_timeless_counter(counter)
  Timeless[name] = (counter == 0) ? nil : counter
end
timeless() click to toggle source

Begin an execution that should skip timestamping.

@example Create a document but don’t timestamp.

Person.timeless.create(:title => "Sir")

@return [ Class ] The class this was called on.

# 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?() click to toggle source

Returns whether the current class should skip timestamping.

@return [ true | false ] Whether the current class should

skip timestamping.
# File lib/mongoid/timestamps/timeless.rb, line 121
def timeless?
  !!Timeless[name]
end