Sha256: 939af15c6888a9704ad9c85655fa4b1b67c3d7169ceaa0ecbe23b64f00605898

Contents?: true

Size: 1.05 KB

Versions: 27

Compression:

Stored size: 1.05 KB

Contents

# frozen_string_literal: true
# encoding: utf-8

module Mongoid
  module Persistable

    # Defines behavior for $unset operations.
    #
    # @since 4.0.0
    module Unsettable
      extend ActiveSupport::Concern

      # Perform an $unset operation on the provided fields and in the
      # values in the document in memory.
      #
      # @example Unset the values.
      #   document.unset(:first_name, :last_name, :middle)
      #
      # @param [ Array<String, Symbol> ] fields The names of the fields to
      #   unset.
      #
      # @return [ Document ] The document.
      #
      # @since 4.0.0
      def unset(*fields)
        prepare_atomic_operation do |ops|
          fields.flatten.each do |field|
            normalized = database_field_name(field)
            if executing_atomically?
              process_attribute normalized, nil
            else
              attributes.delete(normalized)
            end
            ops[atomic_attribute_name(normalized)] = true
          end
          { "$unset" => ops }
        end
      end
    end
  end
end

Version data entries

27 entries across 27 versions & 2 rubygems

Version Path
mongoid-7.3.5 lib/mongoid/persistable/unsettable.rb
mongoid-7.3.4 lib/mongoid/persistable/unsettable.rb
mongoid-7.1.11 lib/mongoid/persistable/unsettable.rb
mongoid-7.2.6 lib/mongoid/persistable/unsettable.rb
mongoid-7.3.3 lib/mongoid/persistable/unsettable.rb
mongoid-7.3.2 lib/mongoid/persistable/unsettable.rb
mongoid-7.2.5 lib/mongoid/persistable/unsettable.rb
mongoid-7.1.10 lib/mongoid/persistable/unsettable.rb
mongoid-7.1.9 lib/mongoid/persistable/unsettable.rb
mongoid-7.2.4 lib/mongoid/persistable/unsettable.rb
mongoid-7.3.1 lib/mongoid/persistable/unsettable.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/mongoid-7.1.7/lib/mongoid/persistable/unsettable.rb
mongoid-7.3.0 lib/mongoid/persistable/unsettable.rb
mongoid-7.2.3 lib/mongoid/persistable/unsettable.rb
mongoid-7.1.8 lib/mongoid/persistable/unsettable.rb
mongoid-7.2.2 lib/mongoid/persistable/unsettable.rb
mongoid-7.2.1 lib/mongoid/persistable/unsettable.rb
mongoid-7.1.7 lib/mongoid/persistable/unsettable.rb
mongoid-7.2.0 lib/mongoid/persistable/unsettable.rb
mongoid-7.1.6 lib/mongoid/persistable/unsettable.rb