Class: Low::Mongo::Remote

Inherits:
Object
  • Object
show all
Includes:
Low::Mongo
Defined in:
lib/low/mongo.rb

Overview

For connecting to Mongo via a URI.

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#uriObject (readonly)

Returns the value of attribute uri.



69
70
71
# File 'lib/low/mongo.rb', line 69

def uri
  @uri
end

Instance Method Details

#connectionObject

and use it to connect.



77
78
79
# File 'lib/low/mongo.rb', line 77

def connection
  @connection ||= ::Mongo::Connection.from_uri(uri)
end

#databaseObject

The database can be extracted from the URI,



82
83
84
# File 'lib/low/mongo.rb', line 82

def database
  @uri.match(/.*\/(.*)$/)[1]
end

#passwordObject

and password.



94
95
96
97
98
# File 'lib/low/mongo.rb', line 94

def password
  if match = @uri.match(/^.*:\/\/.*?:(.*?)@.*/)
    match[1]
  end
end

#usernameObject

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