class Mongoid::Sessions::MongoUri
Constants
- DATABASE
- NODES
- PASS
- SCHEME
- URI
- USER
Attributes
match[R]
Public Class Methods
new(string)
click to toggle source
Create the new uri from the provided string.
@example Create the new uri.
MongoUri.new(uri)
@param [ String ] string The uri string.
@since 3.0.0
# File lib/mongoid/sessions/mongo_uri.rb, line 47 def initialize(string) @match = string.match(URI) end
Public Instance Methods
database()
click to toggle source
Get the database provided in the URI.
@example Get the database.
uri.database
@return [ String ] The database.
@since 3.0.0
# File lib/mongoid/sessions/mongo_uri.rb, line 23 def database @database ||= match[9] end
hosts()
click to toggle source
Get the hosts provided in the URI.
@example Get the hosts.
uri.hosts
@return [ Array<String> ] The hosts.
@since 3.0.0
# File lib/mongoid/sessions/mongo_uri.rb, line 35 def hosts @hosts ||= match[5].split(",") end
password()
click to toggle source
Get the password provided in the URI.
@example Get the password.
uri.password
@return [ String ] The password.
@since 3.0.0
# File lib/mongoid/sessions/mongo_uri.rb, line 59 def password @password ||= match[4] end
to_hash()
click to toggle source
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 3.0.0
# File lib/mongoid/sessions/mongo_uri.rb, line 71 def to_hash config = { database: database, hosts: hosts } if username && password config.merge!(username: username, password: password) end config end
username()
click to toggle source
Get the username provided in the URI.
@example Get the username.
uri.username
@return [ String ] The username.
@since 3.0.0
# File lib/mongoid/sessions/mongo_uri.rb, line 87 def username @username ||= match[3] end