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

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

Instance Method Summary collapse

Instance Method Details

#clear_timeless_optionObject



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

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

#clear_timeless_option_on_updateObject



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

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



85
86
87
# File 'build/mongoid-8.1/lib/mongoid/timestamps/timeless.rb', line 85

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.



61
62
63
64
65
66
67
# File 'build/mongoid-8.1/lib/mongoid/timestamps/timeless.rb', line 61

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:



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

def timeless?
  !!Timeless[name]
end