Class Moped::Uri
In: lib/moped/uri.rb
Parent: Object

Parses MongoDB uri

@since 1.3.0

Methods

Constants

SCHEME = /(mongodb:\/\/)/   Get the scheme pattern.

@since 1.3.0

USER = /([-.\w:]+)/   The user name pattern.

@since 1.3.0

PASS = /([^@,]+)/   The password pattern.

@since 1.3.0

NODES = /((([-.\w]+)(?::(\w+))?,?)+)/   The nodes pattern.

@since 1.3.0

DATABASE = /(?:\/([-\w]+))?/   The database pattern.

@since 1.3.0

OPTIONS = /(?:\?(.+))/   The options pattern.

@since 1.3.0

URI = /#{SCHEME}(#{USER}:#{PASS}@)?#{NODES}#{DATABASE}#{OPTIONS}?/   The full URI pattern.

@since 1.3.0

WRITE_OPTIONS = [ "w", "j", "fsync", "wtimeout" ].freeze   The options that have to do with write concerns.

@since 2.0.0

READ_MAPPINGS = { "nearest" => :nearest, "primary" => :primary, "primarypreferred" => :primary_preferred, "secondary" => :secondary, "secondarypreferred" => :secondary_preferred   The mappings from read preferences in the URI to Moped‘s.

@since 2.0.0

Attributes

match  [R]  @!attribute match
  @return [ Array ] The uri match.

Public Class methods

Create the new uri from the provided string.

@example Create the new uri.

  MongoUri.new(uri)

@param [ String ] string The uri string.

@since 1.3.0

Public Instance methods

Helper to determine if authentication is provided

@example Boolean response if username/password given

  uri.auth_provided?

@return [ true, false ] If authorization is provided.

@since 1.3.0

Get the database provided in the URI.

@example Get the database.

  uri.database

@return [ String ] The database.

@since 1.3.0

Get the hosts provided in the URI.

@example Get the hosts.

  uri.hosts

@return [ Array<String> ] The hosts.

@since 1.3.0

Raise a human readable error when improper URI provided

@example Raise error and provide guidance on invalid URI

  MongoUri.invalid!(uri)

@param [ String ] Invalid string

@since 1.3.1

Create Moped usable arguments

@example Get the moped args

  uri.moped_arguments

@return [ Array ] Array of arguments usable by Moped

@since 1.3.0

Get the options provided in the URI.

@example Get the options

  uri.options

@note The options provided in the URI string must match the MongoDB

  specification.

@return [ Hash ] Options hash usable by Moped

@see docs.mongodb.org/manual/reference/connection-string/#connections-connection-options

@since 1.3.0

Get the password provided in the URI.

@example Get the password.

  uri.password

@return [ String ] The password.

@since 1.3.0

Get the uri as a Mongoid friendly configuration hash.

@example Get the uri as a hash.

  uri.to_hash

@return [ Hash ] The uri as options.

@since 1.3.0

Get the username provided in the URI.

@example Get the username.

  uri.username

@return [ String ] The username.

@since 1.3.0

[Validate]