Method: Mongo::Client#update_options

Defined in:
lib/mongo/client.rb

#update_options(new_options) ⇒ Hash

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Updates this client’s options from new_options, validating all options.

The new options may be transformed according to various rules. The final hash of options actually applied to the client is returned.

If options fail validation, this method may warn or raise an exception. If this method raises an exception, the client should be discarded (similarly to if a constructor raised an exception).

Parameters:

  • new_options (Hash)

    The new options to use.

Returns:

  • (Hash)

    Modified new options written into the client.

Since:

  • 2.0.0



810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
# File 'lib/mongo/client.rb', line 810

def update_options(new_options)
  old_options = @options

  new_options = self.class.canonicalize_ruby_options(new_options || {})

  validate_new_options!(new_options).tap do |opts|
    # Our options are frozen
    options = @options.dup
    if options[:write] && opts[:write_concern]
      options.delete(:write)
    end
    if options[:write_concern] && opts[:write]
      options.delete(:write_concern)
    end

    options.update(opts)
    @options = options.freeze

    auto_encryption_options_changed =
      @options[:auto_encryption_options] != old_options[:auto_encryption_options]

    # If there are new auto_encryption_options, create a new encrypter.
    # Otherwise, allow the new client to share an encrypter with the
    # original client.
    #
    # If auto_encryption_options are nil, set @encrypter to nil, but do not
    # close the encrypter because it may still be used by the original client.
    if @options[:auto_encryption_options] && auto_encryption_options_changed
      @connect_lock.synchronize do
        build_encrypter
      end
    elsif @options[:auto_encryption_options].nil?
      @connect_lock.synchronize do
        @encrypter = nil
      end
    end

    validate_options!
    validate_authentication_options!
  end
end