Class: Low::Mongo::Remote
- Inherits:
-
Object
- Object
- Low::Mongo::Remote
- Includes:
- Low::Mongo
- Defined in:
- lib/low/mongo.rb
Overview
For connecting to Mongo via a URI.
Instance Attribute Summary collapse
-
#uri ⇒ Object
readonly
Returns the value of attribute uri.
Instance Method Summary collapse
-
#connection ⇒ Object
and use it to connect.
-
#database ⇒ Object
The database can be extracted from the URI,.
-
#initialize(uri) ⇒ Remote
constructor
Specify the remote URI upon initialization.
-
#password ⇒ Object
and password.
-
#username ⇒ Object
as can the username,.
Methods included from Low::Mongo
#[], #db, #grid, #host, #reset_connection!
Constructor Details
#initialize(uri) ⇒ Remote
Specify the remote URI upon initialization
72 73 74 |
# File 'lib/low/mongo.rb', line 72 def initialize(uri) @uri = uri end |
Instance Attribute Details
#uri ⇒ Object (readonly)
Returns the value of attribute uri.
69 70 71 |
# File 'lib/low/mongo.rb', line 69 def uri @uri end |
Instance Method Details
#connection ⇒ Object
and use it to connect.
77 78 79 |
# File 'lib/low/mongo.rb', line 77 def connection @connection ||= ::Mongo::Connection.from_uri(uri) end |
#database ⇒ Object
The database can be extracted from the URI,
82 83 84 |
# File 'lib/low/mongo.rb', line 82 def database @uri.match(/.*\/(.*)$/)[1] end |
#password ⇒ Object
and password.
94 95 96 97 98 |
# File 'lib/low/mongo.rb', line 94 def password if match = @uri.match(/^.*:\/\/.*?:(.*?)@.*/) match[1] end end |
#username ⇒ Object
as can the username,
87 88 89 90 91 |
# File 'lib/low/mongo.rb', line 87 def username if match = @uri.match(/^.*:\/\/(.*?):.*/) match[1] end end |