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.27 lib/workarea/ext/mongoid/timestamps_timeless.rb
workarea-core-3.5.26 lib/workarea/ext/mongoid/timestamps_timeless.rb
workarea-core-3.4.45 lib/workarea/ext/mongoid/timestamps_timeless.rb
workarea-core-3.5.25 lib/workarea/ext/mongoid/timestamps_timeless.rb
workarea-core-3.5.23 lib/workarea/ext/mongoid/timestamps_timeless.rb
workarea-core-3.4.44 lib/workarea/ext/mongoid/timestamps_timeless.rb
workarea-core-3.5.22 lib/workarea/ext/mongoid/timestamps_timeless.rb
workarea-core-3.4.43 lib/workarea/ext/mongoid/timestamps_timeless.rb
workarea-core-3.5.21 lib/workarea/ext/mongoid/timestamps_timeless.rb
workarea-core-3.4.42 lib/workarea/ext/mongoid/timestamps_timeless.rb
workarea-core-3.5.20 lib/workarea/ext/mongoid/timestamps_timeless.rb
workarea-core-3.4.41 lib/workarea/ext/mongoid/timestamps_timeless.rb
workarea-core-3.5.19 lib/workarea/ext/mongoid/timestamps_timeless.rb
workarea-core-3.4.40 lib/workarea/ext/mongoid/timestamps_timeless.rb
workarea-core-3.5.18 lib/workarea/ext/mongoid/timestamps_timeless.rb
workarea-core-3.4.39 lib/workarea/ext/mongoid/timestamps_timeless.rb
workarea-core-3.5.17 lib/workarea/ext/mongoid/timestamps_timeless.rb
workarea-core-3.4.38 lib/workarea/ext/mongoid/timestamps_timeless.rb
workarea-core-3.5.16 lib/workarea/ext/mongoid/timestamps_timeless.rb
workarea-core-3.4.37 lib/workarea/ext/mongoid/timestamps_timeless.rb