@@ -435,9 +435,9 @@ def self.uri_option(uri_key, name, extra = {})
435435
436436 # Write Options
437437 uri_option 'w' , :w , :group => :write
438- uri_option 'journal' , :j , :group => :write , :type => :bool
438+ uri_option 'journal' , :j , :group => :write , :type => :journal
439439 uri_option 'fsync' , :fsync , :group => :write
440- uri_option 'wtimeoutms' , :timeout , :group => :write , :type => :unsigned_int
440+ uri_option 'wtimeoutms' , :timeout , :group => :write , :type => :wtimeout
441441
442442 # Read Options
443443 uri_option 'readpreference' , :mode , :group => :read , :type => :read_mode
@@ -452,7 +452,7 @@ def self.uri_option(uri_key, name, extra = {})
452452 # Security Options
453453 uri_option 'ssl' , :ssl
454454 uri_option 'tls' , :ssl
455- uri_option 'tlsallowinvalidcertificates' , :ssl_verify , :type => :inverse_bool
455+ uri_option 'tlsallowinvalidcertificates' , :ssl_verify , :type => :ssl_verify
456456 uri_option 'tlscafilepath' , :ssl_ca_cert
457457 uri_option 'tlsclientcertfilepath' , :ssl_cert
458458 uri_option 'tlsclientkeyfilepath' , :ssl_key
@@ -471,7 +471,7 @@ def self.uri_option(uri_key, name, extra = {})
471471 uri_option 'appname' , :app_name
472472 uri_option 'compressors' , :compressors , :type => :array
473473 uri_option 'readconcernlevel' , :read_concern
474- uri_option 'retrywrites' , :retry_writes , :type => :bool
474+ uri_option 'retrywrites' , :retry_writes , :type => :retry_writes
475475 uri_option 'zlibcompressionlevel' , :zlib_compression_level , :type => :zlib_compression_level
476476
477477 # Casts option values that do not have a specifically provided
@@ -582,7 +582,9 @@ def auth_source(value)
582582 #
583583 # @return [Symbol] The transformed authentication mechanism.
584584 def auth_mech ( value )
585- AUTH_MECH_MAP [ value . upcase ] || log_warn ( "#{ value } is not a valid auth mechanism" )
585+ AUTH_MECH_MAP [ value . upcase ] . tap do |mech |
586+ log_warn ( "#{ value } is not a valid auth mechanism" ) unless mech
587+ end
586588 end
587589
588590 # Read preference mode transformation.
@@ -631,9 +633,9 @@ def auth_mech_props(value)
631633 # @param value [ String ] The zlib compression level string.
632634 #
633635 # @return [ Integer | nil ] The compression level value if it is between -1 and 9 (inclusive),
634- # otherwise nil (and a warning will be raised ).
636+ # otherwise nil (and a warning will be logged ).
635637 def zlib_compression_level ( value )
636- if /^ -?\d +$ / =~ value
638+ if /\A -?\d +\z / =~ value
637639 i = value . to_i
638640
639641 if i >= -1 && i <= 9
@@ -645,47 +647,69 @@ def zlib_compression_level(value)
645647 nil
646648 end
647649
650+ # Parses the journal value.
651+ #
652+ # @param value [ String ] The journal value.
653+ #
654+ # @return [ true | false | nil ] The journal value parsed out, otherwise nil (and a warning
655+ # will be raised).
656+ def journal ( value )
657+ bool ( 'journal' , value )
658+ end
659+
660+ # Parses the ssl_verify value. Note that this will be the inverse of the value of
661+ # tlsAllowInvalidCertificates (if present).
662+ #
663+ # @param value [ String ] The tlsAllowInvalidCertificates value.
664+ #
665+ # @return [ true | false | nil ] The ssl_verify value parsed out, otherwise nil (and a warning
666+ # will be raised).
667+ def ssl_verify ( value )
668+ b = bool ( 'tlsAllowInvalidCertificates' , value )
669+
670+ if b . nil?
671+ nil
672+ else
673+ !b
674+ end
675+ end
676+
677+ # Parses the retryWrites value.
678+ #
679+ # @param value [ String ] The retryWrites value.
680+ #
681+ # @return [ true | false | nil ] The boolean value parsed out, otherwise nil (and a warning
682+ # will be raised).
683+ def retry_writes ( value )
684+ bool ( 'retryWrites' , value )
685+ end
648686
649687 # Parses a boolean value.
650688 #
651689 # @param value [ String ] The URI option value.
652690 #
653691 # @return [ true | false | nil ] The boolean value parsed out, otherwise nil (and a warning
654692 # will be raised).
655- def bool ( value )
693+ def bool ( name , value )
656694 case value
657695 when "true"
658696 true
659697 when "false"
660698 false
661699 else
662- log_warn ( "invalid boolean: #{ value } " )
700+ log_warn ( "invalid boolean option for #{ name } : #{ value } " )
663701 nil
664702 end
665703 end
666704
667- # Parses a boolean value and returns its inverse. This is used for options where the spec
668- # defines the boolean value semantics of enabling/disabling something in the reverse way that
669- # the driver does. For instance, the client option `ssl_verify` will disable certificate
670- # checking when the value is false, but the spec defines the option
671- # `tlsAllowInvalidCertificates`, which disables certificate checking when the value is true.
672- #
673- # @param value [ String ] The URI option.
674- #
675- # @return [ true | false | nil ] The inverse of boolean value parsed out, otherwise nil (and a
676- # warning will be raised).
677- def inverse_bool ( value )
678- !bool ( value )
679- end
680-
681705 # Parses the max staleness value, which must be either "0" or an integer greater or equal to 90.
682706 #
683707 # @param value [ String ] The max staleness string.
684708 #
685709 # @return [ Integer | nil ] The max staleness integer parsed out if it is valid, otherwise nil
686- # (and a warning will be raised ).
710+ # (and a warning will be logged ).
687711 def max_staleness ( value )
688- if /^ \d +$ / =~ value
712+ if /\A \d + \z / =~ value
689713 int = value . to_i
690714
691715 if int >= 0 && int < 90
@@ -705,9 +729,9 @@ def max_staleness(value)
705729 #
706730 # @return [ Integer | nil ] The integer parsed out, otherwise nil (and a warning will be
707731 # raised).
708- def unsigned_int ( value )
709- unless /^? \d +$ / =~ value
710- log_warn ( "Invalid unsigned integer value: #{ value } " )
732+ def wtimeout ( value )
733+ unless /\A \d + \z / =~ value
734+ log_warn ( "Invalid wtimeoutMS value: #{ value } " )
711735 return nil
712736 end
713737
@@ -724,7 +748,7 @@ def unsigned_int(value)
724748 #
725749 # @since 2.0.0
726750 def ms_convert ( value )
727- unless /^ -?\d +(\. \d +)?$ / =~ value
751+ unless /\A -?\d +(\. \d +)?\z / =~ value
728752 log_warn ( "Invalid ms value: #{ value } " )
729753 return nil
730754 end
0 commit comments