Skip to content

Commit

Permalink
get db from uri string
Browse files Browse the repository at this point in the history
  • Loading branch information
erithmetic committed Jan 21, 2011
1 parent 3f7058a commit 3a2712b
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/moneta/adapters/mongodb.rb
Expand Up @@ -4,6 +4,7 @@
puts "You need the mongo gem to use the MongoDB moneta store"
exit
end
require 'uri'

module Moneta
module Adapters
Expand All @@ -13,6 +14,7 @@ class MongoDB
def initialize(options = {})
if options[:uri]
conn = Mongo::Connection.from_uri options[:uri]
db = conn.db(URI.parse(options[:url]).gsub('/','_'))
else
options = {
:host => ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost',
Expand All @@ -21,8 +23,8 @@ def initialize(options = {})
:collection => 'cache'
}.update(options)
conn = Mongo::Connection.new(options[:host], options[:port])
db = conn.db(options[:db])
end
db = options[:db] ? conn.db(options[:db]) : conn.db
@cache = db.collection(options[:collection])
end

Expand Down

0 comments on commit 3a2712b

Please sign in to comment.