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

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

Instance Method Summary collapse

Instance Method Details

#clear_timeless_optionObject



72
73
74
75
76
77
78
# File 'build/mongoid-7.0/lib/mongoid/timestamps/timeless.rb', line 72

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

#clear_timeless_option_on_updateObject



80
81
82
83
84
85
86
# File 'build/mongoid-7.0/lib/mongoid/timestamps/timeless.rb', line 80

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



88
89
90
# File 'build/mongoid-7.0/lib/mongoid/timestamps/timeless.rb', line 88

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



64
65
66
67
68
69
70
# File 'build/mongoid-7.0/lib/mongoid/timestamps/timeless.rb', line 64

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:



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

def timeless?
  !!Timeless[name]
end