Sha256: 4d9523d28527ec5f8e7ff4d6dd7be3b113e7d7a088f0bd7dae0e50934bd74a05
Contents?: true
Size: 1.85 KB
Versions: 17
Compression:
Stored size: 1.85 KB
Contents
# encoding: utf-8 module Mongoid module Timestamps # This module adds behaviour for turning off timestamping in single or # multiple calls. module Timeless extend ActiveSupport::Concern # Clears out the timeless option. # # @example Clear the timeless option. # document.clear_timeless_option # # @return [ true ] True. # # @since 3.1.4 def clear_timeless_option self.class.clear_timeless_option end # Begin an execution that should skip timestamping. # # @example Save a document but don't timestamp. # person.timeless.save # # @return [ Document ] The document this was called on. # # @since 2.3.0 def timeless self.class.timeless self end def timeless? self.class.timeless? end class << self def timeless_table Thread.current['[mongoid]:timeless'] ||= Hash.new end delegate :[]=, :[], to: :timeless_table end private module ClassMethods # 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. # # @since 2.3.0 def timeless counter = 0 counter += 1 if self < Mongoid::Timestamps::Created counter += 1 if self < Mongoid::Timestamps::Updated Timeless[name] = counter self end def clear_timeless_option if counter = Timeless[name] counter -= 1 Timeless[name] = (counter == 0) ? nil : counter end true end def timeless? !!Timeless[name] end end end end end
Version data entries
17 entries across 17 versions & 3 rubygems