Skip to content

Commit

Permalink
adding ability to set db in config instead of passing in pieces. easi…
Browse files Browse the repository at this point in the history
…er to do replsets this way
  • Loading branch information
Pete Brumm committed Apr 22, 2011
1 parent 300c9c9 commit 9ae2702
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions lib/rack/gridfs.rb 100644 → 100755
Expand Up @@ -5,7 +5,7 @@ module Rack
class GridFSConnectionError < StandardError ; end

class GridFS
VERSION = "0.2.0"
VERSION = "0.2.1"

def initialize(app, options = {})
options = {
Expand All @@ -18,7 +18,7 @@ def initialize(app, options = {})
@app = app
@prefix = options[:prefix].gsub(/^\//, '')
@lookup = options[:lookup]
@db = nil
@db = options[:db]

@hostname, @port, @database, @username, @password =
options.values_at(:hostname, :port, :database, :username, :password)
Expand All @@ -38,8 +38,10 @@ def call(env)
private
def connect!
Timeout::timeout(5) do
@db = Mongo::Connection.new(@hostname, @port).db(@database)
@db.authenticate(@username, @password) if @username
if @db.nil?
@db = Mongo::Connection.new(@hostname, @port).db(@database)
@db.authenticate(@username, @password) if @username
end
end
rescue Exception => e
raise Rack::GridFSConnectionError, "Unable to connect to the MongoDB server (#{e.to_s})"
Expand Down

0 comments on commit 9ae2702

Please sign in to comment.