mongoid/moped — pull request #118 by Winslett (2012-11-22 15:09:18+00:00)
Title: Give a better response when a poor URI is provided

I was bitten by my own feature. I entered an improper URI and was greeted with:

/Users/chris/Projects/moped/lib/moped/mongo_uri.rb:53:in `hosts': undefined method `[]' for nil:NilClass (NoMethodError)
from /Users/chris/Projects/moped/lib/moped/mongo_uri.rb:134:in `moped_arguments'
from /Users/chris/Projects/moped/lib/moped/session.rb:332:in `connect'
from -e:1:in `

'

With this pull, when you enter an invalid MongoURI, it fails quickly and gracefully:

/Users/chris/Projects/moped/lib/moped/mongo_uri.rb:95:in `invalid_uri!': (Moped::Errors::InvalidMongoURI)
The given connection string is invalid:
mongo://localasdf

MongoDB connection strings must be of the format:
mongodb://host:port/database

For authentication, include username and password before host:
mongodb://username:password@host:port/database

For Replica Sets, include multiple host:port entries:
mongodb://host:port,host2:port2/database

For options, use query string syntax with the option value:
mongodb://host:port/database?safe=true&max_retries=30&timeout=5

from /Users/chris/Projects/moped/lib/moped/mongo_uri.rb:66:in `initialize'
from /Users/chris/Projects/moped/lib/moped/session.rb:331:in `new'
from /Users/chris/Projects/moped/lib/moped/session.rb:331:in `connect'
from -e:1:in `

'

I was a little verbose on the help just to give full knowledge of MongoDB syntax. Scale back as you wish.