Module: Mongoid::Timestamps::Timeless::ClassMethods

Defined in:
build/mongoid-7.3/lib/mongoid/timestamps/timeless.rb

Instance Method Summary collapse

Instance Method Details

#clear_timeless_optionObject



76
77
78
79
80
81
82
# File 'build/mongoid-7.3/lib/mongoid/timestamps/timeless.rb', line 76

def clear_timeless_option
  if counter = Timeless[name]
    counter -= 1
    set_timeless_counter(counter)
  end
  true
end

#clear_timeless_option_on_updateObject



84
85
86
87
88
89
90
# File 'build/mongoid-7.3/lib/mongoid/timestamps/timeless.rb', line 84

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) ⇒ Object



92
93
94
# File 'build/mongoid-7.3/lib/mongoid/timestamps/timeless.rb', line 92

def set_timeless_counter(counter)
  Timeless[name] = (counter == 0) ? nil : counter
end

#timelessClass

Begin an execution that should skip timestamping.

Examples:

Create a document but don’t timestamp.

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

Returns:

  • (Class)

    The class this was called on.

Since:

  • 2.3.0



68
69
70
71
72
73
74
# File 'build/mongoid-7.3/lib/mongoid/timestamps/timeless.rb', line 68

def timeless
  counter = 0
  counter += 1 if self < Mongoid::Timestamps::Created
  counter += 1 if self < Mongoid::Timestamps::Updated
  Timeless[name] = counter
  self
end

#timeless?Boolean

Returns:



96
97
98
# File 'build/mongoid-7.3/lib/mongoid/timestamps/timeless.rb', line 96

def timeless?
  !!Timeless[name]
end