lib/mongo/uri.rb in mongo-2.0.6 vs lib/mongo/uri.rb in mongo-2.1.0.beta

- old
+ new

@@ -25,10 +25,11 @@ # client.login(uri.credentials) # client[uri.database] # # @since 2.0.0 class URI + include Loggable # Scheme Regex: non-capturing, matches scheme. # # @since 2.0.0 SCHEME = %r{(?:mongodb://)}.freeze @@ -67,11 +68,11 @@ # be part of any MongoDB database name. # # @since 2.0.0 DATABASE = %r{(?:/([^/\.\ "*<>:\|\?]*))?}.freeze - # Option Regex: notably only matches the ampersand separator and does + # Option Regex: only matches the ampersand separator and does # not allow for semicolon to be used to separate options. # # @since 2.0.0 OPTIONS = /(?:\?(?:(.+=.+)&?)+)*/.freeze @@ -121,11 +122,12 @@ # # @raise [ BadURI ] If the uri does not match the spec. # # @since 2.0.0 def initialize(string) - @match = string.match(URI) + @string = string + @match = @string.match(URI) raise Error::InvalidURI.new(string) unless @match end # Get the servers provided in the URI. # @@ -208,12 +210,17 @@ parsed_options = @match[5] return {} unless parsed_options parsed_options.split('&').reduce({}) do |options, option| key, value = option.split('=') strategy = OPTION_MAP[key] - raise Error::InvalidURIOption.new(key) if strategy.nil? - add_option(strategy, value, options) + if strategy.nil? + log_warn([ + "Unsupported URI option '#{key}' on URI '#{@string}'. It will be ignored." + ]) + else + add_option(strategy, value, options) + end options end end private @@ -241,10 +248,10 @@ option 'serverSelectionTimeoutMS', :server_selection_timeout, :type => :ms_convert option 'localThresholdMS', :local_threshold, :type => :ms_convert # Write Options option 'w', :w, :group => :write - option 'j', :j, :group => :write + option 'journal', :j, :group => :write option 'fsync', :fsync, :group => :write option 'wtimeoutMS', :timeout, :group => :write # Read Options option 'readPreference', :mode, :group => :read, :type => :read_mode