Class Mongo::URIParser
In: lib/mongo/util/uri_parser.rb
Parent: Object

Methods

Constants

USER_REGEX = /([-.\w:]+)/
PASS_REGEX = /([^@,]+)/
AUTH_REGEX = /(#{USER_REGEX}:#{PASS_REGEX}@)?/
HOST_REGEX = /([-.\w]+)/
PORT_REGEX = /(?::(\w+))?/
NODE_REGEX = /((#{HOST_REGEX}#{PORT_REGEX},?)+)/
PATH_REGEX = /(?:\/([-\w]+))?/
MONGODB_URI_MATCHER = /#{AUTH_REGEX}#{NODE_REGEX}#{PATH_REGEX}/
MONGODB_URI_SPEC = "mongodb://[username:password@]host1[:port1][,host2[:port2],...[,hostN[:portN]]][/[database][?options]]"
SPEC_ATTRS = [:nodes, :auths]
READ_PREFERENCES = { "primary" => :primary, "primarypreferred" => :primary_preferred, "secondary" => :secondary, "secondarypreferred" => :secondary_preferred, "nearest" => :nearest
OPT_ATTRS = [ :connect, :connecttimeoutms, :fsync, :journal, :pool_size, :readpreference, :replicaset, :safe, :slaveok, :sockettimeoutms, :ssl, :w, :wtimeout, :wtimeoutms
OPT_VALID = { :connect => lambda { |arg| [ 'direct', 'replicaset', 'true', 'false', true, false ].include?(arg) }, :connecttimeoutms => lambda { |arg| arg =~ /^\d+$/ }, :fsync => lambda { |arg| ['true', 'false'].include?(arg) }, :journal => lambda { |arg| ['true', 'false'].include?(arg) }, :pool_size => lambda { |arg| arg.to_i > 0 }, :readpreference => lambda { |arg| READ_PREFERENCES.keys.include?(arg) }, :replicaset => lambda { |arg| arg.length > 0 }, :safe => lambda { |arg| ['true', 'false'].include?(arg) }, :slaveok => lambda { |arg| ['true', 'false'].include?(arg) }, :sockettimeoutms => lambda { |arg| arg =~ /^\d+$/ }, :ssl => lambda { |arg| ['true', 'false'].include?(arg) }, :w => lambda { |arg| arg =~ /^\w+$/ }, :wtimeout => lambda { |arg| arg =~ /^\d+$/ }, :wtimeoutms => lambda { |arg| arg =~ /^\d+$/ }
OPT_ERR = { :connect => "must be 'direct', 'replicaset', 'true', or 'false'", :connecttimeoutms => "must be an integer specifying milliseconds", :fsync => "must be 'true' or 'false'", :journal => "must be 'true' or 'false'", :pool_size => "must be an integer greater than zero", :readpreference => "must be on of #{READ_PREFERENCES.keys.map(&:inspect).join(",")}", :replicaset => "must be a string containing the name of the replica set to connect to", :safe => "must be 'true' or 'false'", :slaveok => "must be 'true' or 'false'", :sockettimeoutms => "must be an integer specifying milliseconds", :ssl => "must be 'true' or 'false'", :w => "must be an integer indicating number of nodes to replicate to or a string " + "specifying that replication is required to the majority or nodes with a " + "particilar getLastErrorMode.", :wtimeout => "must be an integer specifying milliseconds", :wtimeoutms => "must be an integer specifying milliseconds"
OPT_CONV = { :connect => lambda { |arg| arg == 'false' ? false : arg }, # convert 'false' to FalseClass :connecttimeoutms => lambda { |arg| arg.to_f / 1000 }, # stored as seconds :fsync => lambda { |arg| arg == 'true' ? true : false }, :journal => lambda { |arg| arg == 'true' ? true : false }, :pool_size => lambda { |arg| arg.to_i }, :readpreference => lambda { |arg| READ_PREFERENCES[arg] }, :replicaset => lambda { |arg| arg }, :safe => lambda { |arg| arg == 'true' ? true : false }, :slaveok => lambda { |arg| arg == 'true' ? true : false }, :sockettimeoutms => lambda { |arg| arg.to_f / 1000 }, # stored as seconds :ssl => lambda { |arg| arg == 'true' ? true : false }, :w => lambda { |arg| Mongo::Support.is_i?(arg) ? arg.to_i : arg.to_sym }, :wtimeout => lambda { |arg| arg.to_i }, :wtimeoutms => lambda { |arg| arg.to_i }

Attributes

auths  [R] 
connect  [R] 
connecttimeoutms  [R] 
fsync  [R] 
journal  [R] 
nodes  [R] 
pool_size  [R] 
readpreference  [R] 
replicaset  [R] 
safe  [R] 
slaveok  [R] 
sockettimeoutms  [R] 
ssl  [R] 
w  [R] 
wtimeout  [R] 
wtimeoutms  [R] 

Public Class methods

Parse a MongoDB URI. This method is used by MongoClient.from_uri. Returns an array of nodes and an array of db authorizations, if applicable.

@note Passwords can contain any character except for ’,’

@param [String] uri The MongoDB URI string. @param [Hash,nil] extra_opts Extra options. Will override anything already specified in the URI.

@core connections

Public Instance methods

Whether to immediately connect to the MongoDB node[s]. Defaults to true. @return [true, false]

Create a Mongo::MongoClient or a Mongo::MongoReplicaSetClient based on the URI.

@note Don‘t confuse this with attribute getter method connect.

@return [MongoClient,MongoReplicaSetClient]

Options that can be passed to MongoClient.new or MongoReplicaSetClient.new @return [Hash]

Whether this represents a direct connection.

@note Specifying :connect => ‘direct’ has no effect… other than to raise an exception if other variables suggest a replicaset.

@return [true,false]

For direct connections, the host of the (only) node. @return [String]

For direct connections, the port of the (only) node. @return [Integer]

Whether this represents a replica set. @return [true,false]

[Validate]