Sha256: 1235486dd598ae2d95927768d198c27487a9a30bb76dbf21a1340d4baf0069b4

Contents?: true

Size: 1.34 KB

Versions: 62

Compression:

Stored size: 1.34 KB

Contents

# see https://github.com/mongoid/mongoid/pull/4110
# This can be removed after the above PR is accepted and the version in the Gemfile is bumped to one the includes the PR. The test that was committed along with this will verify that the Gem upgrade fixes the issue.

module Mongoid
  module Timestamps

    module Created
      def set_created_at
        if !timeless? && !created_at
          time = Time.current.utc
          self.updated_at = time if is_a?(Updated) && !updated_at_changed?
          self.created_at = time
        end

        clear_timeless_option
      end
    end

    module Updated
      def set_updated_at
        if able_to_set_updated_at?
          self.updated_at = Time.current.utc unless updated_at_changed?
        end

        clear_timeless_option
      end
    end

    module Timeless
      def clear_timeless_option
        if self.persisted?
          self.class.clear_timeless_option_on_update
        else
          self.class.clear_timeless_option
        end
        true
      end

      module ClassMethods

        def clear_timeless_option_on_update
          if counter = Timeless[name]
            counter -= 1 if self < Mongoid::Timestamps::Created
            counter -= 1 if self < Mongoid::Timestamps::Updated
            Timeless[name] = (counter == 0) ? nil : counter
          end
        end
      end
    end
  end
end

Version data entries

62 entries across 62 versions & 1 rubygems

Version Path
workarea-core-3.5.15 lib/workarea/ext/mongoid/timestamps_timeless.rb
workarea-core-3.4.36 lib/workarea/ext/mongoid/timestamps_timeless.rb
workarea-core-3.5.14 lib/workarea/ext/mongoid/timestamps_timeless.rb
workarea-core-3.4.35 lib/workarea/ext/mongoid/timestamps_timeless.rb
workarea-core-3.5.13 lib/workarea/ext/mongoid/timestamps_timeless.rb
workarea-core-3.4.34 lib/workarea/ext/mongoid/timestamps_timeless.rb
workarea-core-3.5.12 lib/workarea/ext/mongoid/timestamps_timeless.rb
workarea-core-3.4.33 lib/workarea/ext/mongoid/timestamps_timeless.rb
workarea-core-3.5.11 lib/workarea/ext/mongoid/timestamps_timeless.rb
workarea-core-3.5.10 lib/workarea/ext/mongoid/timestamps_timeless.rb
workarea-core-3.4.32 lib/workarea/ext/mongoid/timestamps_timeless.rb
workarea-core-3.5.9 lib/workarea/ext/mongoid/timestamps_timeless.rb
workarea-core-3.4.31 lib/workarea/ext/mongoid/timestamps_timeless.rb
workarea-core-3.5.8 lib/workarea/ext/mongoid/timestamps_timeless.rb
workarea-core-3.4.30 lib/workarea/ext/mongoid/timestamps_timeless.rb
workarea-core-3.5.7 lib/workarea/ext/mongoid/timestamps_timeless.rb
workarea-core-3.4.29 lib/workarea/ext/mongoid/timestamps_timeless.rb
workarea-core-3.5.6 lib/workarea/ext/mongoid/timestamps_timeless.rb
workarea-core-3.4.28 lib/workarea/ext/mongoid/timestamps_timeless.rb
workarea-core-3.5.5 lib/workarea/ext/mongoid/timestamps_timeless.rb