Class: Mongo::URI
Overview
The URI class provides a way for users to parse the MongoDB uri as defined in the connection string format spec.
Constant Summary collapse
- UNSAFE =
Unsafe characters that must be urlencoded.
/[\:\/\+\@]/
- UNIX_SOCKET =
Unix socket suffix.
/.sock/
- SCHEME =
The mongodb connection string scheme.
'mongodb://'.freeze
- HOST_DELIM =
The character delimiting hosts.
','.freeze
- HOST_PORT_DELIM =
The character separating a host and port.
':'.freeze
- DATABASE_DELIM =
The character delimiting a database.
'/'.freeze
- URI_OPTS_DELIM =
The character delimiting options.
'?'.freeze
- INDIV_URI_OPTS_DELIM =
The character delimiting multiple options.
'&'.freeze
- URI_OPTS_VALUE_DELIM =
The character delimiting an option and its value.
'='.freeze
- AUTH_USER_PWD_DELIM =
The character separating a username from the password.
':'.freeze
- AUTH_DELIM =
The character delimiting auth credentials.
'@'.freeze
- INVALID_SCHEME =
Error details for an invalid scheme.
"Invalid scheme. Scheme must be '#{SCHEME}'".freeze
- INVALID_OPTS_VALUE_DELIM =
Error details for an invalid options format.
"Options and their values must be delimited" + " by '#{URI_OPTS_VALUE_DELIM}'".freeze
- UNESCAPED_USER_PWD =
Error details for an non-urlencoded user name or password.
"User name and password must be urlencoded.".freeze
- UNESCAPED_UNIX_SOCKET =
Error details for a non-urlencoded unix socket path.
"UNIX domain sockets must be urlencoded.".freeze
- UNESCAPED_DATABASE =
Error details for a non-urlencoded auth databsae name.
"Auth database must be urlencoded.".freeze
- INVALID_OPTS_DELIM =
Error details for providing options without a database delimiter.
"Database delimiter '#{DATABASE_DELIM}' must be present if options are specified.".freeze
- INVALID_HOST =
Error details for a missing host.
"Missing host; at least one must be provided.".freeze
- INVALID_PORT =
Error details for an invalid port.
"Invalid port. Port must be an integer greater than 0 and less than 65536".freeze
- FORMAT =
MongoDB URI format specification.
'mongodb://[username:password@]host1[:port1][,host2[:port2]' + ',...[,hostN[:portN]]][/[database][?options]]'.freeze
- HELP =
MongoDB URI (connection string) documentation url
'http://docs.mongodb.org/manual/reference/connection-string/'.freeze
- READ_MODE_MAP =
Map of URI read preference modes to ruby driver read preference modes
{ 'primary' => :primary, 'primaryPreferred' => :primary_preferred, 'secondary' => :secondary, 'secondaryPreferred' => :secondary_preferred, 'nearest' => :nearest }.freeze
- AUTH_MECH_MAP =
Map of URI authentication mechanisms to ruby driver mechanisms
{ 'PLAIN' => :plain, 'MONGODB-CR' => :mongodb_cr, 'GSSAPI' => :gssapi }.freeze
- REPEATABLE_OPTIONS =
Options that are allowed to appear more than once in the uri.
[ :tag_sets ]
Constants included from Loggable
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
The uri parser object options.
-
#servers ⇒ Object
readonly
The servers specified in the uri.
-
#uri_options ⇒ Object
readonly
The options specified in the uri.
Instance Method Summary collapse
-
#client_options ⇒ Hash
Gets the options hash that needs to be passed to a Mongo::Client on instantiation, so we don’t have to merge the credentials and database in at that point - we only have a single point here.
-
#credentials ⇒ Hash
Get the credentials provided in the URI.
-
#database ⇒ String
Get the database provided in the URI.
-
#initialize(string, options = {}) ⇒ URI
constructor
Create the new uri from the provided string.
Methods included from Loggable
#log_debug, #log_error, #log_fatal, #log_info, #log_warn, #logger
Constructor Details
#initialize(string, options = {}) ⇒ URI
Create the new uri from the provided string.
192 193 194 195 196 197 198 |
# File 'lib/mongo/uri.rb', line 192 def initialize(string, = {}) @string = string @options = empty, scheme, remaining = @string.partition(SCHEME) raise_invalid_error!(INVALID_SCHEME) unless scheme == SCHEME setup!(remaining) end |
Instance Attribute Details
#options ⇒ Object (readonly)
The uri parser object options.
37 38 39 |
# File 'lib/mongo/uri.rb', line 37 def @options end |
#servers ⇒ Object (readonly)
The servers specified in the uri.
47 48 49 |
# File 'lib/mongo/uri.rb', line 47 def servers @servers end |
#uri_options ⇒ Object (readonly)
The options specified in the uri.
42 43 44 |
# File 'lib/mongo/uri.rb', line 42 def @uri_options end |
Instance Method Details
#client_options ⇒ Hash
Gets the options hash that needs to be passed to a Mongo::Client on instantiation, so we don’t have to merge the credentials and database in at that point - we only have a single point here.
210 211 212 213 |
# File 'lib/mongo/uri.rb', line 210 def opts = .merge(:database => database) @user ? opts.merge(credentials) : opts end |
#credentials ⇒ Hash
Get the credentials provided in the URI.
225 226 227 |
# File 'lib/mongo/uri.rb', line 225 def credentials { :user => @user, :password => @password } end |