Class: Mongo::URI::OptionsMapper Private
| Relationships & Source Files | |
| Super Chains via Extension / Inclusion / Inheritance | |
|
Instance Chain:
self,
::Mongo::Loggable
|
|
| 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::URIoptions are converted to Ruby options. - The mapping from downcased
::Mongo::URIoption names to canonical-cased::Mongo::URIoption names. - Methods to perform conversion of
::Mongo::URIoption 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).
Constant Summary
-
URI_OPTION_CANONICAL_NAMES =
# File 'lib/mongo/uri/options_mapper.rb', line 200
{} -
URI_OPTION_MAP =
# File 'lib/mongo/uri/options_mapper.rb', line 195
Hash for storing map of
::Mongo::URIoption parameters to conversion strategies{}
::Mongo::Loggable - Included
Class Method Summary
-
.new(**opts) ⇒ OptionsMapper
constructor
Internal use only
Instantiates the options mapper.
-
.uri_option(uri_key, name, **extra)
Internal use only
Simple internal dsl to register a MongoDB URI option in the URI_OPTION_MAP.
Instance Attribute Summary
- #options ⇒ Hash readonly Internal use only
Instance Method Summary
-
#add_uri_option(key, value, uri_options, offset: nil)
Internal use only
Adds an option to the uri options hash.
-
#ruby_to_smc(opts) ⇒ Hash
Internal use only
Converts Ruby options provided to "standardized MongoClient options".
-
#ruby_to_string(opts) ⇒ Hash
Internal use only
Converts Ruby options provided to their representation in a
::Mongo::URIstring. - #smc_to_ruby(opts) Internal use only
-
#apply_transform(key, value, type)
private
Internal use only
Applies URI value transformation by either using the default cast or a transformation appropriate for the given type.
-
#convert_array(_name, value) ⇒ Array<String>
private
Internal use only
Extract values from the string and put them into an array.
-
#convert_auth_mech(name, value) ⇒ Symbol
private
Internal use only
Authentication mechanism transformation.
-
#convert_auth_mech_props(_name, value) ⇒ Hash | nil
private
Internal use only
::Mongo::Authmechanism properties extractor. -
#convert_bool(name, value) ⇒ true | false | nil
private
Internal use only
Converts
valueto a boolean. -
#convert_integer(name, value) ⇒ nil | Integer
private
Internal use only
Converts
valueinto an integer. -
#convert_inverse_bool(name, value) ⇒ true | false | nil
private
Internal use only
Parses a boolean value and returns its inverse.
-
#convert_max_staleness(name, value) ⇒ Integer | nil
private
Internal use only
Parses the max staleness value, which must be either "0" or an integer greater or equal to 90.
-
#convert_ms(name, value) ⇒ Float
private
Internal use only
Ruby's convention is to provide timeouts in seconds, not milliseconds and to use fractions where more precision is necessary.
-
#convert_read_mode(_name, value) ⇒ Symbol | String
private
Internal use only
Read preference mode transformation.
-
#convert_read_set(_name, value) ⇒ Hash
private
Internal use only
Read preference tag set extractor.
-
#convert_read_tags(name, value) ⇒ Array<Hash> | nil
private
Internal use only
Read preference tags transformation.
-
#convert_repeated_bool(_name, value) ⇒ Array<true | false | nil>
private
Internal use only
Converts the value into a boolean and returns it wrapped in an array.
-
#convert_server_monitoring_mode(name, value) ⇒ Symbol | nil
private
Internal use only
::Mongo::Servermonitoring mode transformation. -
#convert_symbol(_name, value) ⇒ Symbol
private
Internal use only
Converts
valueinto a symbol. -
#convert_w(_name, value) ⇒ Integer | Symbol | String
private
Internal use only
Converts
valueas a write concern. -
#convert_zlib_compression_level(name, value) ⇒ Integer | nil
private
Internal use only
Parses the zlib compression level.
-
#hash_extractor(name, value, invalidate_on_error: false) ⇒ Hash | nil
private
Internal use only
Extract values from the string and put them into a nested hash.
-
#merge_uri_option(target, value, name, canonical_key)
private
Internal use only
Merges a new option into the target.
-
#revert_array(value) ⇒ Array<String>
private
Internal use only
Reverts an array.
-
#revert_auth_mech(value) ⇒ String
private
Internal use only
Reverts auth mechanism.
-
#revert_auth_mech_props(value) ⇒ Hash | nil
private
Internal use only
Reverts auth mechanism properties.
-
#revert_bool(value) ⇒ true | false | nil
private
Internal use only
Reverts a boolean type.
-
#revert_integer(value) ⇒ Integer | nil
private
Internal use only
Reverts an integer.
-
#revert_inverse_bool(value) ⇒ true | false | nil
private
Internal use only
Reverts and inverts a boolean type.
-
#revert_max_staleness(value) ⇒ Integer | nil
private
Internal use only
Reverts max staleness.
-
#revert_ms(value) ⇒ Integer
private
Internal use only
Reverts an ms.
-
#revert_read_mode(value) ⇒ String
(also: #stringify_read_mode)
private
Internal use only
Reverts read mode.
-
#revert_read_tags(value) ⇒ Array<Hash> | nil
private
Internal use only
Reverts read tags.
-
#revert_repeated_bool(value) ⇒ Array<true | false> | true | false | nil
private
Internal use only
Reverts a repeated boolean type.
-
#revert_symbol(value) ⇒ String
(also: #stringify_symbol)
private
Internal use only
Reverts a symbol.
-
#revert_w(value) ⇒ Integer | String
private
Internal use only
Reverts write concern.
-
#revert_zlib_compression_level(value) ⇒ Integer | nil
private
Internal use only
Reverts zlib compression level.
-
#stringify_array(value) ⇒ String
private
Internal use only
Stringifies an array.
-
#stringify_auth_mech(value) ⇒ String | nil
private
Internal use only
Stringifies auth mechanism.
-
#stringify_auth_mech_props(value) ⇒ String | nil
private
Internal use only
Stringifies auth mechanism properties.
-
#stringify_bool(value) ⇒ String | nil
private
Internal use only
Stringifies a boolean type.
-
#stringify_integer(value) ⇒ String | nil
private
Internal use only
Stringifies an integer.
-
#stringify_inverse_bool(value) ⇒ String | nil
private
Internal use only
Inverts and stringifies a boolean.
-
#stringify_max_staleness(value) ⇒ String | nil
private
Internal use only
Stringifies max staleness.
-
#stringify_ms(value) ⇒ String
private
Internal use only
Stringifies an ms.
-
#stringify_read_mode(value)
private
Alias for #revert_read_mode.
-
#stringify_read_tags(value) ⇒ String | nil
private
Internal use only
Stringifies read tags.
-
#stringify_repeated_bool(value) ⇒ Array<true | false> | nil
private
Internal use only
Stringifies a repeated boolean type.
-
#stringify_server_monitoring_mode(value) ⇒ String
private
Internal use only
Stringifies server monitoring mode.
-
#stringify_symbol(value)
private
Alias for #revert_symbol.
-
#stringify_w(value) ⇒ String
private
Internal use only
Stringifies write concern.
-
#stringify_zlib_compression_level(value) ⇒ String | nil
private
Internal use only
Stringifies zlib compression level.
-
#unsupported_option_message(offset = nil) ⇒ String
private
Internal use only
Builds a warning about an option the driver does not know.
::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 | |
Constructor Details
.new(**opts) ⇒ OptionsMapper
Instantiates the options mapper.
# File 'lib/mongo/uri/options_mapper.rb', line 43
def initialize(**opts) @options = opts end
Class Method Details
.uri_option(uri_key, name, **extra)
Simple internal dsl to register a MongoDB URI option in the URI_OPTION_MAP.
# File 'lib/mongo/uri/options_mapper.rb', line 210
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
#options ⇒ Hash (readonly)
# File 'lib/mongo/uri/options_mapper.rb', line 48
attr_reader :
Instance Method Details
#add_uri_option(key, value, uri_options, offset: nil)
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.
# File 'lib/mongo/uri/options_mapper.rb', line 62
def add_uri_option(key, value, , offset: nil) strategy = URI_OPTION_MAP[key.downcase] if strategy.nil? log_warn((offset)) return end canonical_key = URI_OPTION_CANONICAL_NAMES[key.downcase] group = strategy[:group] target = if group [group] || {} else end value = apply_transform(canonical_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. merge_uri_option(target, value, strategy[:name], canonical_key) unless value.nil? return unless group && !target.empty? && !.key?(group) [group] = target 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.
# File 'lib/mongo/uri/options_mapper.rb', line 223
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.
# File 'lib/mongo/uri/options_mapper.rb', line 570
def convert_array(_name, value) value.split(',') end
#convert_auth_mech(name, value) ⇒ Symbol (private)
Authentication mechanism transformation.
# File 'lib/mongo/uri/options_mapper.rb', line 598
def convert_auth_mech(name, value) auth_mech = AUTH_MECH_MAP[value.upcase] (auth_mech || value).tap do |_mech| log_warn("#{name} is not a valid authentication mechanism") unless auth_mech end end
#convert_auth_mech_props(_name, value) ⇒ Hash | nil (private)
::Mongo::Auth mechanism properties extractor.
# File 'lib/mongo/uri/options_mapper.rb', line 638
def convert_auth_mech_props(_name, value) properties = hash_extractor('authMechanismProperties', value, invalidate_on_error: true) if properties properties.each do |k, v| properties[k] = (v.downcase == 'true') if k.to_s.downcase == 'canonicalize_host_name' && v 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.
# File 'lib/mongo/uri/options_mapper.rb', line 347
def convert_bool(name, value) case value when true, 'true', 'TRUE' true when false, 'false', 'FALSE' false else log_warn("Invalid boolean value for #{name}") 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.
# File 'lib/mongo/uri/options_mapper.rb', line 466
def convert_integer(name, value) if value.is_a?(String) && /\A\d+\z/ !~ value log_warn("#{name} is not a valid integer") return nil end value.to_i end
#convert_inverse_bool(name, value) ⇒ true | false | nil (private)
Parses a boolean value and returns its inverse.
# File 'lib/mongo/uri/options_mapper.rb', line 430
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.
# File 'lib/mongo/uri/options_mapper.rb', line 676
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 value for #{name}") return nil end int = nil if int == -1 if int && ((int > 0 && int < 90) || int < 0) log_warn("#{name} should be either 0 or greater than 90") 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.
# File 'lib/mongo/uri/options_mapper.rb', line 503
def convert_ms(name, value) case value when String unless /\A-?\d+(\.\d+)?\z/.match?(value) log_warn("Invalid value for #{name}") 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.
# File 'lib/mongo/uri/options_mapper.rb', line 722
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.
# File 'lib/mongo/uri/options_mapper.rb', line 798
def convert_read_set(_name, value) hash_extractor('readPreferenceTags', value) end
#convert_read_tags(name, value) ⇒ Array<Hash> | nil (private)
Read preference tags transformation.
# File 'lib/mongo/uri/options_mapper.rb', line 767
def (name, value) converted = convert_read_set(name, value) return unless converted [ converted ] end
#convert_repeated_bool(_name, value) ⇒ Array<true | false | nil> (private)
Converts the value into a boolean and returns it wrapped in an array.
tls and ssl are the only repeated_bool options. An invalid value is preserved as a nil element rather than warned-and-dropped, so that URI#validate_uri_options! can detect it and raise instead of silently falling back to a plaintext connection (RUBY-3832).
# File 'lib/mongo/uri/options_mapper.rb', line 389
def convert_repeated_bool(_name, value) case value when true, 'true', 'TRUE' [ true ] when false, 'false', 'FALSE' [ false ] else [ nil ] end end
#convert_server_monitoring_mode(name, value) ⇒ Symbol | nil (private)
::Mongo::Server monitoring mode transformation.
# File 'lib/mongo/uri/options_mapper.rb', line 742
def convert_server_monitoring_mode(name, value) mode = value.downcase if SERVER_MONITORING_MODES.include?(mode) mode.to_sym else log_warn("#{name} is not a valid server monitoring mode") nil end end
#convert_symbol(_name, value) ⇒ Symbol (private)
Converts value into a symbol.
# File 'lib/mongo/uri/options_mapper.rb', line 550
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.
# File 'lib/mongo/uri/options_mapper.rb', line 812
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.
# File 'lib/mongo/uri/options_mapper.rb', line 853
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("#{name} is not a valid compression level") nil end end
#hash_extractor(name, value, invalidate_on_error: false) ⇒ Hash | nil (private)
Extract values from the string and put them into a nested hash.
Multiple key-value pairs are delimited by a comma. Within each pair, the key is everything up to the first colon and the value is everything after it, so values may themselves contain colons (for example TOKEN_RESOURCE:mongodb://host).
# File 'lib/mongo/uri/options_mapper.rb', line 901
def hash_extractor(name, value, invalidate_on_error: false) h = {} value.split(',').each do |tag| k, v = tag.split(':', 2) if v.nil? log_warn("Invalid value for #{name}") return nil if invalidate_on_error next end h[k.to_sym] = v end if h.empty? nil else h end end
#merge_uri_option(target, value, name, canonical_key) (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.
# File 'lib/mongo/uri/options_mapper.rb', line 243
def merge_uri_option(target, value, name, canonical_key) if target.key?(name) if REPEATABLE_OPTIONS.include?(name) target[name] += value else log_warn("Repeated option key: #{canonical_key}.") end else target.merge!(name => value) end end
#revert_array(value) ⇒ Array<String> (private)
Reverts an array.
# File 'lib/mongo/uri/options_mapper.rb', line 579
def revert_array(value) value end
#revert_auth_mech(value) ⇒ String (private)
Reverts auth mechanism.
# File 'lib/mongo/uri/options_mapper.rb', line 612
def revert_auth_mech(value) found = AUTH_MECH_MAP.detect do |_k, v| v == value end raise ArgumentError, "Unknown auth mechanism #{value}" unless found found.first end
#revert_auth_mech_props(value) ⇒ Hash | nil (private)
Reverts auth mechanism properties.
# File 'lib/mongo/uri/options_mapper.rb', line 653
def revert_auth_mech_props(value) value end
#revert_bool(value) ⇒ true | false | nil (private)
Reverts a boolean type.
# File 'lib/mongo/uri/options_mapper.rb', line 364
def revert_bool(value) value end
#revert_integer(value) ⇒ Integer | nil (private)
Reverts an integer.
# File 'lib/mongo/uri/options_mapper.rb', line 480
def revert_integer(value) value end
#revert_inverse_bool(value) ⇒ true | false | nil (private)
Reverts and inverts a boolean type.
# File 'lib/mongo/uri/options_mapper.rb', line 445
def revert_inverse_bool(value) value.nil? ? nil : !value end
#revert_max_staleness(value) ⇒ Integer | nil (private)
Reverts max staleness.
# File 'lib/mongo/uri/options_mapper.rb', line 703
def revert_max_staleness(value) value end
#revert_ms(value) ⇒ Integer (private)
Reverts an ms.
# File 'lib/mongo/uri/options_mapper.rb', line 531
def revert_ms(value) (value * 1000).round end
#revert_read_mode(value) ⇒ String (private)
Also known as: #stringify_read_mode
Reverts read mode.
# File 'lib/mongo/uri/options_mapper.rb', line 731
def revert_read_mode(value) value.to_s.gsub(/_(\w)/) { ::Regexp.last_match(1).upcase } end
#revert_read_tags(value) ⇒ Array<Hash> | nil (private)
Reverts read tags.
# File 'lib/mongo/uri/options_mapper.rb', line 779
def (value) value end
#revert_repeated_bool(value) ⇒ Array<true | false> | true | false | nil (private)
Reverts a repeated boolean type.
# File 'lib/mongo/uri/options_mapper.rb', line 405
def revert_repeated_bool(value) value end
#revert_symbol(value) ⇒ String (private)
Also known as: #stringify_symbol
Reverts a symbol.
# File 'lib/mongo/uri/options_mapper.rb', line 559
def revert_symbol(value) value.to_s end
#revert_w(value) ⇒ Integer | String (private)
Reverts write concern.
#revert_zlib_compression_level(value) ⇒ Integer | nil (private)
Reverts zlib compression level
# File 'lib/mongo/uri/options_mapper.rb', line 873
def revert_zlib_compression_level(value) value end
#ruby_to_smc(opts) ⇒ Hash
Converts Ruby options provided to "standardized MongoClient options".
# File 'lib/mongo/uri/options_mapper.rb', line 122
def ruby_to_smc(opts) rv = {} URI_OPTION_MAP.each do |uri_key, spec| if spec[:group] v = opts[spec[:group]] v &&= v[spec[:name]] else v = opts[spec[:name]] end next if v.nil? if (type = spec[:type]) v = send("revert_#{type}", v) end canonical_key = URI_OPTION_CANONICAL_NAMES[uri_key] raise ArgumentError, "Option #{uri_key} is not known" unless canonical_key rv[canonical_key] = v end # For options that default to true, remove the value if it is true. %w[retryReads retryWrites].each do |k| rv.delete(k) if rv[k] end # Remove auth source when it is $external for mechanisms that default # (or require) that auth source. rv.delete('authSource') if %w[MONGODB-AWS].include?(rv['authMechanism']) && rv['authSource'] == '$external' # 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.
# File 'lib/mongo/uri/options_mapper.rb', line 160
def ruby_to_string(opts) rv = {} URI_OPTION_MAP.each do |uri_key, spec| if spec[:group] v = opts[spec[:group]] v &&= v[spec[:name]] else v = opts[spec[:name]] end next if v.nil? if (type = spec[:type]) v = send("stringify_#{type}", v) end canonical_key = URI_OPTION_CANONICAL_NAMES[uri_key] raise ArgumentError, "Option #{uri_key} is not known" unless canonical_key rv[canonical_key] = v end # For options that default to true, remove the value if it is true. %w[retryReads retryWrites].each do |k| rv.delete(k) if rv[k] end # Remove auth source when it is $external for mechanisms that default # (or require) that auth source. rv.delete('authSource') if %w[MONGODB-AWS].include?(rv['authMechanism']) && rv['authSource'] == '$external' # 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)
# File 'lib/mongo/uri/options_mapper.rb', line 87
def smc_to_ruby(opts) = {} opts.each do |key, value| strategy = URI_OPTION_MAP[key.downcase] if strategy.nil? log_warn() next end canonical_key = URI_OPTION_CANONICAL_NAMES[key.downcase] group = strategy[:group] target = if group [group] || {} else end value = apply_transform(canonical_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. merge_uri_option(target, value, strategy[:name], canonical_key) unless value.nil? [group] = target if group && !target.empty? && !.key?(group) end end
#stringify_array(value) ⇒ String (private)
Stringifies an array.
# File 'lib/mongo/uri/options_mapper.rb', line 588
def stringify_array(value) value.join(',') end
#stringify_auth_mech(value) ⇒ String | nil (private)
Stringifies auth mechanism.
# File 'lib/mongo/uri/options_mapper.rb', line 626
def stringify_auth_mech(value) revert_auth_mech(value) rescue StandardError nil end
#stringify_auth_mech_props(value) ⇒ String | nil (private)
Stringifies auth mechanism properties.
# File 'lib/mongo/uri/options_mapper.rb', line 662
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.
# File 'lib/mongo/uri/options_mapper.rb', line 373
def stringify_bool(value) revert_bool(value)&.to_s end
#stringify_integer(value) ⇒ String | nil (private)
Stringifies an integer.
# File 'lib/mongo/uri/options_mapper.rb', line 489
def stringify_integer(value) revert_integer(value)&.to_s end
#stringify_inverse_bool(value) ⇒ String | nil (private)
Inverts and stringifies a boolean.
# File 'lib/mongo/uri/options_mapper.rb', line 454
def stringify_inverse_bool(value) revert_inverse_bool(value)&.to_s end
#stringify_max_staleness(value) ⇒ String | nil (private)
Stringifies max staleness.
# File 'lib/mongo/uri/options_mapper.rb', line 712
def stringify_max_staleness(value) revert_max_staleness(value)&.to_s end
#stringify_ms(value) ⇒ String (private)
Stringifies an ms.
#stringify_read_mode(value) (private)
Alias for #revert_read_mode.
# File 'lib/mongo/uri/options_mapper.rb', line 734
alias stringify_read_mode revert_read_mode
#stringify_read_tags(value) ⇒ String | nil (private)
Stringifies read tags.
# File 'lib/mongo/uri/options_mapper.rb', line 788
def (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.
# File 'lib/mongo/uri/options_mapper.rb', line 414
def stringify_repeated_bool(value) rep = revert_repeated_bool(value) if rep.is_a?(Array) rep.join(',') else rep end end
#stringify_server_monitoring_mode(value) ⇒ String (private)
Stringifies server monitoring mode.
# File 'lib/mongo/uri/options_mapper.rb', line 757
def stringify_server_monitoring_mode(value) value.to_s end
#stringify_symbol(value) (private)
Alias for #revert_symbol.
# File 'lib/mongo/uri/options_mapper.rb', line 562
alias stringify_symbol revert_symbol
#stringify_w(value) ⇒ String (private)
Stringifies write concern.
#stringify_zlib_compression_level(value) ⇒ String | nil (private)
Stringifies zlib compression level
# File 'lib/mongo/uri/options_mapper.rb', line 882
def stringify_zlib_compression_level(value) revert_zlib_compression_level(value)&.to_s end
#unsupported_option_message(offset = nil) ⇒ String (private)
Builds a warning about an option the driver does not know. The key itself is not included: it comes from the connection string and may contain text the user intended as a credential.
# File 'lib/mongo/uri/options_mapper.rb', line 263
def (offset = nil) if offset "Unsupported option at offset #{offset} in the query segment. It will be ignored." else 'Unsupported option. It will be ignored.' end end