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.4.27 lib/workarea/ext/mongoid/timestamps_timeless.rb
workarea-core-3.5.4 lib/workarea/ext/mongoid/timestamps_timeless.rb
workarea-core-3.4.26 lib/workarea/ext/mongoid/timestamps_timeless.rb
workarea-core-3.5.3 lib/workarea/ext/mongoid/timestamps_timeless.rb
workarea-core-3.4.25 lib/workarea/ext/mongoid/timestamps_timeless.rb
workarea-core-3.5.2 lib/workarea/ext/mongoid/timestamps_timeless.rb
workarea-core-3.4.24 lib/workarea/ext/mongoid/timestamps_timeless.rb
workarea-core-3.5.1 lib/workarea/ext/mongoid/timestamps_timeless.rb
workarea-core-3.4.23 lib/workarea/ext/mongoid/timestamps_timeless.rb
workarea-core-3.4.22 lib/workarea/ext/mongoid/timestamps_timeless.rb
workarea-core-3.5.0 lib/workarea/ext/mongoid/timestamps_timeless.rb
workarea-core-3.4.21 lib/workarea/ext/mongoid/timestamps_timeless.rb
workarea-core-3.5.0.beta.1 lib/workarea/ext/mongoid/timestamps_timeless.rb
workarea-core-3.4.20 lib/workarea/ext/mongoid/timestamps_timeless.rb
workarea-core-3.4.19 lib/workarea/ext/mongoid/timestamps_timeless.rb
workarea-core-3.4.18 lib/workarea/ext/mongoid/timestamps_timeless.rb
workarea-core-3.4.17 lib/workarea/ext/mongoid/timestamps_timeless.rb
workarea-core-3.4.16 lib/workarea/ext/mongoid/timestamps_timeless.rb
workarea-core-3.4.15 lib/workarea/ext/mongoid/timestamps_timeless.rb
workarea-core-3.4.14 lib/workarea/ext/mongoid/timestamps_timeless.rb