Class: Mongoid::Sessions::MongoUri
- Inherits:
-
Object
- Object
- Mongoid::Sessions::MongoUri
- Defined in:
- lib/mongoid/sessions/mongo_uri.rb
Constant Summary collapse
- SCHEME =
/(mongodb:\/\/)/
- USER =
/([-.\w:]+)/
- PASS =
/([^@,]+)/
- NODES =
/((([-.\w]+)(?::(\w+))?,?)+)/
- DATABASE =
/(?:\/([-\w]+))?/
- URI =
/#{SCHEME}(#{USER}:#{PASS}@)?#{NODES}#{DATABASE}/
Instance Attribute Summary collapse
-
#match ⇒ Object
readonly
Returns the value of attribute match.
Instance Method Summary collapse
-
#database ⇒ String
Get the database provided in the URI.
-
#hosts ⇒ Array<String>
Get the hosts provided in the URI.
-
#initialize(string) ⇒ MongoUri
constructor
Create the new uri from the provided string.
-
#password ⇒ String
Get the password provided in the URI.
-
#to_hash ⇒ Hash
Get the uri as a Mongoid friendly configuration hash.
-
#username ⇒ String
Get the username provided in the URI.
Constructor Details
Instance Attribute Details
#match ⇒ Object (readonly)
Returns the value of attribute match.
14 15 16 |
# File 'lib/mongoid/sessions/mongo_uri.rb', line 14 def match @match end |
Instance Method Details
#database ⇒ String
Get the database provided in the URI.
24 25 26 |
# File 'lib/mongoid/sessions/mongo_uri.rb', line 24 def database @database ||= match[9] end |
#hosts ⇒ Array<String>
Get the hosts provided in the URI.
36 37 38 |
# File 'lib/mongoid/sessions/mongo_uri.rb', line 36 def hosts @hosts ||= match[5].split(",") end |
#password ⇒ String
Get the password provided in the URI.
60 61 62 |
# File 'lib/mongoid/sessions/mongo_uri.rb', line 60 def password @password ||= match[4] end |
#to_hash ⇒ Hash
Get the uri as a Mongoid friendly configuration hash.
72 73 74 75 76 77 78 |
# File 'lib/mongoid/sessions/mongo_uri.rb', line 72 def to_hash config = { database: database, hosts: hosts } if username && password config.merge!(username: username, password: password) end config end |
#username ⇒ String
Get the username provided in the URI.
88 89 90 |
# File 'lib/mongoid/sessions/mongo_uri.rb', line 88 def username @username ||= match[3] end |