123456789_123456789_123456789_123456789_123456789_

Class: Mongo::URI::OptionsMapper Private

Do not use. This class is for internal use only.
Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Instance Chain:
Inherits: Object
Defined in: lib/mongo/uri/options_mapper.rb

Overview

Performs mapping between ::Mongo::URI options and Ruby options.

This class contains:

  • The mapping defining how ::Mongo::URI options are converted to Ruby options.

  • The mapping from downcased ::Mongo::URI option names to canonical-cased ::Mongo::URI option names.

  • Methods to perform conversion of ::Mongo::URI option values to Ruby option values (the convert_* methods). These generally warn and return nil when input given is invalid.

  • Methods to perform conversion of Ruby option values to standardized MongoClient options (revert_* methods). These assume the input is valid and generally do not perform validation.

::Mongo::URI option names are case insensitive. Ruby options are specified as symbols (though in ::Mongo::Client options use indifferent access).

Since:

  • 2.0.0

Constant Summary

::Mongo::Loggable - Included

PREFIX

Class Method Summary

Instance Attribute Summary

Instance Method Summary

::Mongo::Loggable - Included

#log_debug

Convenience method to log debug messages with the standard prefix.

#log_error

Convenience method to log error messages with the standard prefix.

#log_fatal

Convenience method to log fatal messages with the standard prefix.

#log_info

Convenience method to log info messages with the standard prefix.

#log_warn

Convenience method to log warn messages with the standard prefix.

#logger

Get the logger instance.

#_mongo_log_prefix, #format_message

Class Method Details

.uri_option(uri_key, name, **extra) (private)

Simple internal dsl to register a MongoDB URI option in the URI_OPTION_MAP.

Parameters:

  • uri_key (String)

    The MongoDB ::Mongo::URI option to register.

  • name (Symbol)

    The name of the option in the driver.

  • extra (Hash)

    Extra options.

    • :group [ ::Symbol ] Nested hash where option will go.

    • :type [ ::Symbol ] Name of function to transform value.

Since:

  • 2.0.0

[ GitHub ]

  
# File 'lib/mongo/uri/options_mapper.rb', line 260

def self.uri_option(uri_key, name, **extra)
  URI_OPTION_MAP[uri_key.downcase] = { name: name }.update(extra)
  URI_OPTION_CANONICAL_NAMES[uri_key.downcase] = uri_key
end

Instance Attribute Details

#optionsHash (readonly)

Returns:

  • (Hash)

    The options.

Since:

  • 2.0.0

[ GitHub ]

  
# File 'lib/mongo/uri/options_mapper.rb', line 51

attr_reader :options

Instance Method Details

#add_uri_option(key, value, uri_options)

Adds an option to the uri options hash.

Acquires a target for the option based on group.
Transforms the value.
Merges the option into the target.

Parameters:

  • key (String)

    ::Mongo::URI option name.

  • value (String)

    The value of the option.

  • uri_options (Hash)

    The base option target.

Since:

  • 2.0.0

[ GitHub ]

  
# File 'lib/mongo/uri/options_mapper.rb', line 62

def add_uri_option(key, value, uri_options)
  strategy = URI_OPTION_MAP[key.downcase]
  if strategy.nil?
    log_warn("Unsupported URI option '#{key}' on URI '#{@string}'. It will be ignored.")
    return
  end

  group = strategy[:group]
  target = if group
    uri_options[group] || {}
  else
    uri_options
  end
  value = apply_transform(key, value, strategy[:type])
  # Sometimes the value here would be nil, for example if we are processing
  # read preference tags or auth mechanism properties and all of the
  # data within is invalid. Ignore such options.
  unless value.nil?
    merge_uri_option(target, value, strategy[:name])
  end

  if group && !target.empty? && !uri_options.key?(group)
    uri_options[group] = target
  end
end

#apply_transform(key, value, type) (private)

Applies URI value transformation by either using the default cast or a transformation appropriate for the given type.

Parameters:

  • key (String)

    ::Mongo::URI option name.

  • value (String)

    The value to be transformed.

  • type (Symbol)

    The transform method.

Since:

  • 2.0.0

[ GitHub ]

  
# File 'lib/mongo/uri/options_mapper.rb', line 215

def apply_transform(key, value, type)
  if type
    send("convert_#{type}", key, value)
  else
    value
  end
end

#convert_array(name, value) ⇒ Array<String> (private)

Extract values from the string and put them into an array.

Parameters:

  • name (String)

    Name of the ::Mongo::URI option being processed.

  • value (String)

    The string to build an array from.

Returns:

  • (Array<String>)

    The array built from the string.

Since:

  • 2.0.0

[ GitHub ]

  
# File 'lib/mongo/uri/options_mapper.rb', line 547

def convert_array(name, value)
  value.split(',')
end

#convert_auth_mech(name, value) ⇒ Symbol (private)

Authentication mechanism transformation.

Parameters:

  • name (String)

    Name of the ::Mongo::URI option being processed.

  • value (String)

    The authentication mechanism.

Returns:

  • (Symbol)

    The transformed authentication mechanism.

Since:

  • 2.0.0

[ GitHub ]

  
# File 'lib/mongo/uri/options_mapper.rb', line 575

def convert_auth_mech(name, value)
  auth_mech = AUTH_MECH_MAP[value.upcase]
  (auth_mech || value).tap do |mech|
    log_warn("#{value} is not a valid auth mechanism") unless auth_mech
  end
end

#convert_auth_mech_props(name, value) ⇒ Hash | nil (private)

::Mongo::Auth mechanism properties extractor.

Parameters:

  • name (String)

    Name of the ::Mongo::URI option being processed.

  • value (String)

    The auth mechanism properties string.

Returns:

  • (Hash | nil)

    The auth mechanism properties hash.

Since:

  • 2.0.0

[ GitHub ]

  
# File 'lib/mongo/uri/options_mapper.rb', line 615

def convert_auth_mech_props(name, value)
  properties = hash_extractor('authMechanismProperties', value)
  if properties
    properties.each do |k, v|
      if k.to_s.downcase == 'canonicalize_host_name' && v
        properties[k] = (v.downcase == 'true')
      end
    end
  end
  properties
end

#convert_bool(name, value) ⇒ true | false | nil (private)

Converts value to a boolean.

Returns true for ‘true’, false for ‘false’, otherwise nil.

Parameters:

  • name (String)

    Name of the ::Mongo::URI option being processed.

  • value (String | true | false)

    ::Mongo::URI option value.

Returns:

  • (true | false | nil)

    Converted value.

Since:

  • 2.0.0

[ GitHub ]

  
# File 'lib/mongo/uri/options_mapper.rb', line 336

def convert_bool(name, value)
  case value
  when true, "true", 'TRUE'
    true
  when false, "false", 'FALSE'
    false
  else
    log_warn("invalid boolean option for #{name}: #{value}")
    nil
  end
end

#convert_integer(name, value) ⇒ nil | Integer (private)

Converts value into an integer. Only converts positive integers.

If the value is not a valid integer, warns and returns nil.

Parameters:

  • name (String)

    Name of the ::Mongo::URI option being processed.

  • value (String | Integer)

    ::Mongo::URI option value.

Returns:

  • (nil | Integer)

    Converted value.

Since:

  • 2.0.0

[ GitHub ]

  
# File 'lib/mongo/uri/options_mapper.rb', line 443

def convert_integer(name, value)
  if value.is_a?(String) && /\A\d+\z/ !~ value
    log_warn("#{value} is not a valid integer for #{name}")
    return nil
  end

  value.to_i
end

#convert_inverse_bool(name, value) ⇒ true | false | nil (private)

Parses a boolean value and returns its inverse.

Parameters:

  • name (String)

    Name of the ::Mongo::URI option being processed.

  • value (String | true | false)

    The URI option value.

Returns:

  • (true | false | nil)

    The inverse of the boolean value parsed out, otherwise nil (and a warning will be logged).

Since:

  • 2.0.0

[ GitHub ]

  
# File 'lib/mongo/uri/options_mapper.rb', line 407

def convert_inverse_bool(name, value)
  b = convert_bool(name, value)

  if b.nil?
    nil
  else
    !b
  end
end

#convert_max_staleness(name, value) ⇒ Integer | nil (private)

Parses the max staleness value, which must be either “0” or an integer greater or equal to 90.

Parameters:

  • name (String)

    Name of the ::Mongo::URI option being processed.

  • value (String | Integer)

    The max staleness string.

Returns:

  • (Integer | nil)

    The max staleness integer parsed out if it is valid, otherwise nil (and a warning will be logged).

Since:

  • 2.0.0

[ GitHub ]

  
# File 'lib/mongo/uri/options_mapper.rb', line 654

def convert_max_staleness(name, value)
  int = if value.is_a?(String) && /\A-?\d+\z/ =~ value
    value.to_i
  elsif value.is_a?(Integer)
    value
  end

  if int.nil?
    log_warn("Invalid max staleness value: #{value}")
    return nil
  end

  if int == -1
    int = nil
  end

  if int && (int > 0 && int < 90 || int < 0)
    log_warn("max staleness should be either 0 or greater than 90: #{value}")
    int = nil
  end

  int
end

#convert_ms(name, value) ⇒ Float (private)

Ruby’s convention is to provide timeouts in seconds, not milliseconds and to use fractions where more precision is necessary. The connection string options are always in MS so we provide an easy conversion type.

Parameters:

  • name (String)

    Name of the ::Mongo::URI option being processed.

  • value (String | Integer | Float)

    The millisecond value.

Returns:

  • (Float)

    The seconds value.

Since:

  • 2.0.0

[ GitHub ]

  
# File 'lib/mongo/uri/options_mapper.rb', line 480

def convert_ms(name, value)
  case value
  when String
    if /\A-?\d+(\.\d+)?\z/ !~ value
      log_warn("Invalid ms value for #{name}: #{value}")
      return nil
    end
    if value.to_s[0] == '-'
      log_warn("#{name} cannot be a negative number")
      return nil
    end
  when Integer, Float
    if value < 0
      log_warn("#{name} cannot be a negative number")
      return nil
    end
  else
    raise ArgumentError, "Can only convert Strings, Integers, or Floats to ms. Given: #{value.class}"
  end

  value.to_f / 1000
end

#convert_read_mode(name, value) ⇒ Symbol | String (private)

Read preference mode transformation.

Parameters:

  • name (String)

    Name of the ::Mongo::URI option being processed.

  • value (String)

    The read mode string value.

Returns:

  • (Symbol | String)

    The read mode.

Since:

  • 2.0.0

[ GitHub ]

  
# File 'lib/mongo/uri/options_mapper.rb', line 702

def convert_read_mode(name, value)
  READ_MODE_MAP[value.downcase] || value
end

#convert_read_set(name, value) ⇒ Hash (private)

Read preference tag set extractor.

Parameters:

  • name (String)

    Name of the ::Mongo::URI option being processed.

  • value (String)

    The tag set string.

Returns:

  • (Hash)

    The tag set hash.

Since:

  • 2.0.0

[ GitHub ]

  
# File 'lib/mongo/uri/options_mapper.rb', line 755

def convert_read_set(name, value)
  hash_extractor('readPreferenceTags', value)
end

#convert_read_tags(name, value) ⇒ Array<Hash> | nil (private)

Read preference tags transformation.

Parameters:

  • name (String)

    Name of the ::Mongo::URI option being processed.

  • value (String)

    The string representing tag set.

Returns:

  • (Array<Hash> | nil)

    Array with tag set.

Since:

  • 2.0.0

[ GitHub ]

  
# File 'lib/mongo/uri/options_mapper.rb', line 722

def convert_read_tags(name, value)
  converted = convert_read_set(name, value)
  if converted
    [converted]
  else
    nil
  end
end

#convert_repeated_bool(name, value) ⇒ Array<true | false> | nil (private)

Converts the value into a boolean and returns it wrapped in an array.

Parameters:

Returns:

  • (Array<true | false> | nil)

    The boolean value parsed and wraped in an array.

Since:

  • 2.0.0

[ GitHub ]

  
# File 'lib/mongo/uri/options_mapper.rb', line 373

def convert_repeated_bool(name, value)
  [convert_bool(name, value)]
end

#convert_symbol(name, value) ⇒ Symbol (private)

Converts value into a symbol.

Parameters:

Returns:

  • (Symbol)

    Converted value.

Since:

  • 2.0.0

[ GitHub ]

  
# File 'lib/mongo/uri/options_mapper.rb', line 527

def convert_symbol(name, value)
  value.to_sym
end

#convert_w(name, value) ⇒ Integer | Symbol | String (private)

Converts value as a write concern.

If value is the word “majority”, returns the symbol :majority. If value is a number, returns the number as an integer. Otherwise returns the string value unchanged.

Parameters:

  • name (String)

    Name of the ::Mongo::URI option being processed.

  • value (String | Integer)

    ::Mongo::URI option value.

Returns:

  • (Integer | Symbol | String)

    Converted value.

Since:

  • 2.0.0

[ GitHub ]

  
# File 'lib/mongo/uri/options_mapper.rb', line 769

def convert_w(name, value)
  case value
  when 'majority'
    :majority
  when /\A[0-9]+\z/
    value.to_i
  else
    value
  end
end

#convert_zlib_compression_level(name, value) ⇒ Integer | nil (private)

Parses the zlib compression level.

Parameters:

  • name (String)

    Name of the ::Mongo::URI option being processed.

  • value (String | Integer)

    The zlib compression level string.

Returns:

  • (Integer | nil)

    The compression level value if it is between -1 and 9 (inclusive), otherwise nil (and a warning will be logged).

Since:

  • 2.0.0

[ GitHub ]

  
# File 'lib/mongo/uri/options_mapper.rb', line 810

def convert_zlib_compression_level(name, value)
  i = if value.is_a?(String) && /\A-?\d+\z/ =~ value
    value.to_i
  elsif value.is_a?(Integer)
    value
  end

  if i && (i >= -1 && i <= 9)
    i
  else
    log_warn("#{value} is not a valid zlibCompressionLevel")
    nil
  end
end

#hash_extractor(name, value) ⇒ Hash (private)

Extract values from the string and put them into a nested hash.

Parameters:

  • name (String)

    Name of the ::Mongo::URI option being processed.

  • value (String)

    The string to build a hash from.

Returns:

  • (Hash)

    The hash built from the string.

Since:

  • 2.0.0

[ GitHub ]

  
# File 'lib/mongo/uri/options_mapper.rb', line 849

def hash_extractor(name, value)
  h = {}
  value.split(',').each do |tag|
    k, v = tag.split(':')
    if v.nil?
      log_warn("Invalid hash value for #{name}: key `#{k}` does not have a value: #{value}")
      next
    end

    h[k.to_sym] = v
  end
  if h.empty?
    nil
  else
    h
  end
end

#merge_uri_option(target, value, name) (private)

Merges a new option into the target.

If the option exists at the target destination the merge will be an addition.

Specifically required to append an additional tag set to the array of tag sets without overwriting the original.

Parameters:

  • target (Hash)

    The destination.

  • value (Object)

    The value to be merged.

  • name (Symbol)

    The name of the option.

Since:

  • 2.0.0

[ GitHub ]

  
# File 'lib/mongo/uri/options_mapper.rb', line 234

def merge_uri_option(target, value, name)
  if target.key?(name)
    if REPEATABLE_OPTIONS.include?(name)
      target[name] += value
    else
      log_warn("Repeated option key: #{name}.")
    end
  else
    target.merge!(name => value)
  end
end

#revert_array(value) ⇒ Array<String> (private)

Reverts an array.

Parameters:

  • value (Array<String>)

    An array of strings.

Returns:

  • (Array<String>)

    The passed value.

Since:

  • 2.0.0

[ GitHub ]

  
# File 'lib/mongo/uri/options_mapper.rb', line 556

def revert_array(value)
  value
end

#revert_auth_mech(value) ⇒ String (private)

Reverts auth mechanism.

Parameters:

  • value (Symbol)

    The auth mechanism.

Returns:

  • (String)

    The auth mechanism as a string.

Raises:

  • (ArgumentError)

    if its an invalid auth mechanism.

Since:

  • 2.0.0

[ GitHub ]

  
# File 'lib/mongo/uri/options_mapper.rb', line 589

def revert_auth_mech(value)
  found = AUTH_MECH_MAP.detect do |k, v|
    v == value
  end
  if found
    found.first
  else
    raise ArgumentError, "Unknown auth mechanism #{value}"
  end
end

#revert_auth_mech_props(value) ⇒ Hash | nil (private)

Reverts auth mechanism properties.

Parameters:

  • value (Hash | nil)

    The auth mech properties.

Returns:

  • (Hash | nil)

    The passed value.

Since:

  • 2.0.0

[ GitHub ]

  
# File 'lib/mongo/uri/options_mapper.rb', line 632

def revert_auth_mech_props(value)
  value
end

#revert_bool(value) ⇒ true | false | nil (private)

Reverts a boolean type.

Parameters:

  • value (true | false | nil)

    The boolean to revert.

Returns:

  • (true | false | nil)

    The passed value.

Since:

  • 2.0.0

[ GitHub ]

  
# File 'lib/mongo/uri/options_mapper.rb', line 353

def revert_bool(value)
  value
end

#revert_integer(value) ⇒ Integer | nil (private)

Reverts an integer.

Parameters:

  • value (Integer | nil)

    The integer.

Returns:

  • (Integer | nil)

    The passed value.

Since:

  • 2.0.0

[ GitHub ]

  
# File 'lib/mongo/uri/options_mapper.rb', line 457

def revert_integer(value)
  value
end

#revert_inverse_bool(value) ⇒ true | false | nil (private)

Reverts and inverts a boolean type.

Parameters:

  • value (true | false | nil)

    The boolean to revert and invert.

Returns:

  • (true | false | nil)

    The inverted boolean.

Since:

  • 2.0.0

[ GitHub ]

  
# File 'lib/mongo/uri/options_mapper.rb', line 422

def revert_inverse_bool(value)
  value.nil? ? nil : !value
end

#revert_max_staleness(value) ⇒ Integer | nil (private)

Reverts max staleness.

Parameters:

  • value (Integer | nil)

    The max staleness.

Returns:

  • (Integer | nil)

    The passed value.

Since:

  • 2.0.0

[ GitHub ]

  
# File 'lib/mongo/uri/options_mapper.rb', line 683

def revert_max_staleness(value)
  value
end

#revert_ms(value) ⇒ Integer (private)

Reverts an ms.

Parameters:

  • value (Float)

    The float.

Returns:

  • (Integer)

    The number multiplied by 1000 as an integer.

Since:

  • 2.0.0

[ GitHub ]

  
# File 'lib/mongo/uri/options_mapper.rb', line 508

def revert_ms(value)
  (value * 1000).round
end

#revert_read_mode(value) ⇒ String (private) Also known as: #stringify_read_mode

Reverts read mode.

Parameters:

  • value (Symbol | String)

    The read mode.

Returns:

  • (String)

    The read mode as a string.

Since:

  • 2.0.0

[ GitHub ]

  
# File 'lib/mongo/uri/options_mapper.rb', line 711

def revert_read_mode(value)
  value.to_s.gsub(/_(\w)/) { $1.upcase }
end

#revert_read_tags(value) ⇒ Array<Hash> | nil (private)

Reverts read tags.

Parameters:

  • value (Array<Hash> | nil)

    The read tags.

Returns:

  • (Array<Hash> | nil)

    The passed value.

Since:

  • 2.0.0

[ GitHub ]

  
# File 'lib/mongo/uri/options_mapper.rb', line 736

def revert_read_tags(value)
  value
end

#revert_repeated_bool(value) ⇒ Array<true | false> | true | false | nil (private)

Reverts a repeated boolean type.

Parameters:

  • value (Array<true | false> | true | false | nil)

    The repeated boolean to revert.

Returns:

  • (Array<true | false> | true | false | nil)

    The passed value.

Since:

  • 2.0.0

[ GitHub ]

  
# File 'lib/mongo/uri/options_mapper.rb', line 382

def revert_repeated_bool(value)
  value
end

#revert_symbol(value) ⇒ String (private) Also known as: #stringify_symbol

Reverts a symbol.

Parameters:

  • value (Symbol)

    The symbol.

Returns:

  • (String)

    The passed value as a string.

Since:

  • 2.0.0

[ GitHub ]

  
# File 'lib/mongo/uri/options_mapper.rb', line 536

def revert_symbol(value)
  value.to_s
end

#revert_w(value) ⇒ Integer | String (private)

Reverts write concern.

Parameters:

  • value (Integer | Symbol | String)

    The write concern.

Returns:

  • (Integer | String)

    The write concern as a string.

Since:

  • 2.0.0

[ GitHub ]

  
# File 'lib/mongo/uri/options_mapper.rb', line 785

def revert_w(value)
  case value
  when Symbol
    value.to_s
  else
    value
  end
end

#revert_zlib_compression_level(value) ⇒ Integer | nil (private)

Reverts zlib compression level

Parameters:

  • value (Integer | nil)

    The write concern.

Returns:

  • (Integer | nil)

    The passed value.

Since:

  • 2.0.0

[ GitHub ]

  
# File 'lib/mongo/uri/options_mapper.rb', line 830

def revert_zlib_compression_level(value)
  value
end

#ruby_to_smc(opts) ⇒ Hash

Converts Ruby options provided to “standardized MongoClient options”.

Parameters:

  • opts (Hash)

    Ruby options to convert.

Returns:

  • (Hash)

    Standardized MongoClient options.

Since:

  • 2.0.0

[ GitHub ]

  
# File 'lib/mongo/uri/options_mapper.rb', line 126

def ruby_to_smc(opts)
  rv = {}
  URI_OPTION_MAP.each do |uri_key, spec|
    if spec[:group]
      v = opts[spec[:group]]
      v = v && v[spec[:name]]
    else
      v = opts[spec[:name]]
    end
    unless v.nil?
      if type = spec[:type]
        v = send("revert_#{type}", v)
      end
      canonical_key = URI_OPTION_CANONICAL_NAMES[uri_key]
      unless canonical_key
        raise ArgumentError, "Option #{uri_key} is not known"
      end
      rv[canonical_key] = v
    end
  end
  # For options that default to true, remove the value if it is true.
  %w(retryReads retryWrites).each do |k|
    if rv[k]
      rv.delete(k)
    end
  end
  # Remove auth source when it is $external for mechanisms that default
  # (or require) that auth source.
  if %w(MONGODB-AWS).include?(rv['authMechanism']) && rv['authSource'] == '$external'
    rv.delete('authSource')
  end
  # ssl and tls are aliases, remove ssl ones
  rv.delete('ssl')
  # TODO remove authSource if it is the same as the database,
  # requires this method to know the database specified in the client.
  rv
end

#ruby_to_string(opts) ⇒ Hash

Converts Ruby options provided to their representation in a ::Mongo::URI string.

Parameters:

  • opts (Hash)

    Ruby options to convert.

Returns:

Since:

  • 2.0.0

[ GitHub ]

  
# File 'lib/mongo/uri/options_mapper.rb', line 169

def ruby_to_string(opts)
  rv = {}
  URI_OPTION_MAP.each do |uri_key, spec|
    if spec[:group]
      v = opts[spec[:group]]
      v = v && v[spec[:name]]
    else
      v = opts[spec[:name]]
    end
    unless v.nil?
      if type = spec[:type]
        v = send("stringify_#{type}", v)
      end
      canonical_key = URI_OPTION_CANONICAL_NAMES[uri_key]
      unless canonical_key
        raise ArgumentError, "Option #{uri_key} is not known"
      end
      rv[canonical_key] = v
    end
  end
  # For options that default to true, remove the value if it is true.
  %w(retryReads retryWrites).each do |k|
    if rv[k]
      rv.delete(k)
    end
  end
  # Remove auth source when it is $external for mechanisms that default
  # (or require) that auth source.
  if %w(MONGODB-AWS).include?(rv['authMechanism']) && rv['authSource'] == '$external'
    rv.delete('authSource')
  end
  # ssl and tls are aliases, remove ssl ones
  rv.delete('ssl')
  # TODO remove authSource if it is the same as the database,
  # requires this method to know the database specified in the client.
  rv
end

#smc_to_ruby(opts)

Since:

  • 2.0.0

[ GitHub ]

  
# File 'lib/mongo/uri/options_mapper.rb', line 88

def smc_to_ruby(opts)
  uri_options = {}

  opts.each do |key, value|
    strategy = URI_OPTION_MAP[key.downcase]
    if strategy.nil?
      log_warn("Unsupported URI option '#{key}' on URI '#{@string}'. It will be ignored.")
      return
    end

    group = strategy[:group]
    target = if group
      uri_options[group] || {}
    else
      uri_options
    end

    value = apply_transform(key, value, strategy[:type])
    # Sometimes the value here would be nil, for example if we are processing
    # read preference tags or auth mechanism properties and all of the
    # data within is invalid. Ignore such options.
    unless value.nil?
      merge_uri_option(target, value, strategy[:name])
    end

    if group && !target.empty? && !uri_options.key?(group)
      uri_options[group] = target
    end
  end

  uri_options
end

#stringify_array(value) ⇒ String (private)

Stringifies an array.

Parameters:

  • value (Array<String>)

    An array of strings.

Returns:

  • (String)

    The array joined by commas.

Since:

  • 2.0.0

[ GitHub ]

  
# File 'lib/mongo/uri/options_mapper.rb', line 565

def stringify_array(value)
  value.join(',')
end

#stringify_auth_mech(value) ⇒ String | nil (private)

Stringifies auth mechanism.

Parameters:

  • value (Symbol)

    The auth mechanism.

Returns:

  • (String | nil)

    The auth mechanism as a string.

Since:

  • 2.0.0

[ GitHub ]

  
# File 'lib/mongo/uri/options_mapper.rb', line 605

def stringify_auth_mech(value)
  revert_auth_mech(value) rescue nil
end

#stringify_auth_mech_props(value) ⇒ String | nil (private)

Stringifies auth mechanism properties.

Parameters:

  • value (Hash | nil)

    The auth mech properties.

Returns:

  • (String | nil)

    The string.

Since:

  • 2.0.0

[ GitHub ]

  
# File 'lib/mongo/uri/options_mapper.rb', line 641

def stringify_auth_mech_props(value)
  return if value.nil?
  value.map { |k, v| "#{k}:#{v}" }.join(',')
end

#stringify_bool(value) ⇒ String | nil (private)

Stringifies a boolean type.

Parameters:

  • value (true | false | nil)

    The boolean.

Returns:

  • (String | nil)

    The string.

Since:

  • 2.0.0

[ GitHub ]

  
# File 'lib/mongo/uri/options_mapper.rb', line 362

def stringify_bool(value)
  revert_bool(value)&.to_s
end

#stringify_integer(value) ⇒ String | nil (private)

Stringifies an integer.

Parameters:

  • value (Integer | nil)

    The integer.

Returns:

  • (String | nil)

    The string.

Since:

  • 2.0.0

[ GitHub ]

  
# File 'lib/mongo/uri/options_mapper.rb', line 466

def stringify_integer(value)
  revert_integer(value)&.to_s
end

#stringify_inverse_bool(value) ⇒ String | nil (private)

Inverts and stringifies a boolean.

Parameters:

  • value (true | false | nil)

    The boolean.

Returns:

  • (String | nil)

    The string.

Since:

  • 2.0.0

[ GitHub ]

  
# File 'lib/mongo/uri/options_mapper.rb', line 431

def stringify_inverse_bool(value)
  revert_inverse_bool(value)&.to_s
end

#stringify_max_staleness(value) ⇒ String | nil (private)

Stringifies max staleness.

Parameters:

  • value (Integer | nil)

    The max staleness.

Returns:

  • (String | nil)

    The string.

Since:

  • 2.0.0

[ GitHub ]

  
# File 'lib/mongo/uri/options_mapper.rb', line 692

def stringify_max_staleness(value)
  revert_max_staleness(value)&.to_s
end

#stringify_ms(value) ⇒ String (private)

Stringifies an ms.

Parameters:

  • value (Float)

    The float.

Returns:

  • (String)

    The string.

Since:

  • 2.0.0

[ GitHub ]

  
# File 'lib/mongo/uri/options_mapper.rb', line 517

def stringify_ms(value)
  revert_ms(value).to_s
end

#stringify_read_mode(value) (private)

Alias for #revert_read_mode.

[ GitHub ]

  
# File 'lib/mongo/uri/options_mapper.rb', line 714

alias :stringify_read_mode :revert_read_mode

#stringify_read_tags(value) ⇒ String | nil (private)

Stringifies read tags.

Parameters:

  • value (Array<Hash> | nil)

    The read tags.

Returns:

  • (String | nil)

    The joined string of read tags.

Since:

  • 2.0.0

[ GitHub ]

  
# File 'lib/mongo/uri/options_mapper.rb', line 745

def stringify_read_tags(value)
  value&.map { |ar| ar.map { |k, v| "#{k}:#{v}" }.join(',') }
end

#stringify_repeated_bool(value) ⇒ Array<true | false> | nil (private)

Stringifies a repeated boolean type.

Parameters:

  • value (Array<true | false> | nil)

    The repeated boolean.

Returns:

  • (Array<true | false> | nil)

    The string.

Since:

  • 2.0.0

[ GitHub ]

  
# File 'lib/mongo/uri/options_mapper.rb', line 391

def stringify_repeated_bool(value)
  rep = revert_repeated_bool(value)
  if rep&.is_a?(Array)
    rep.join(",")
  else
    rep
  end
end

#stringify_symbol(value) (private)

Alias for #revert_symbol.

[ GitHub ]

  
# File 'lib/mongo/uri/options_mapper.rb', line 539

alias :stringify_symbol :revert_symbol

#stringify_w(value) ⇒ String (private)

Stringifies write concern.

Parameters:

  • value (Integer | Symbol | String)

    The write concern.

Returns:

  • (String)

    The write concern as a string.

Since:

  • 2.0.0

[ GitHub ]

  
# File 'lib/mongo/uri/options_mapper.rb', line 799

def stringify_w(value)
  revert_w(value)&.to_s
end

#stringify_zlib_compression_level(value) ⇒ String | nil (private)

Stringifies zlib compression level

Parameters:

  • value (Integer | nil)

    The write concern.

Returns:

  • (String | nil)

    The string.

Since:

  • 2.0.0

[ GitHub ]

  
# File 'lib/mongo/uri/options_mapper.rb', line 839

def stringify_zlib_compression_level(value)
  revert_zlib_compression_level(value)&.to_s
end