Skip to content

Commit

Permalink
Defer connection until first use, instead of at configuration-time.
Browse files Browse the repository at this point in the history
This is necessary for use with Thin, as it doesn't start the EventMachine reactor until the first request.
Note that, by default, the Railtie will still force the connection at initialization-time, but this can be overriden.
  • Loading branch information
CodeMonkeySteve authored and durran committed Oct 7, 2010
1 parent cf1ef88 commit a04d568
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions lib/mongoid/config.rb
Expand Up @@ -103,7 +103,10 @@ def master=(db)
#
# The master +Mongo::DB+
def master
raise Errors::InvalidDatabase.new(nil) unless @master
unless @master
_master(@settings)
raise Errors::InvalidDatabase.new(nil) unless @master
end
if @reconnect
@reconnect = false
reconnect!
Expand Down Expand Up @@ -142,6 +145,7 @@ def slaves=(dbs)
#
# The slave +Mongo::DBs+
def slaves
_slaves(@settings) unless @slaves
@slaves
end

Expand Down Expand Up @@ -194,8 +198,7 @@ def from_hash(settings)
settings.except("database", "slaves").each_pair do |name, value|
send("#{name}=", value) if respond_to?("#{name}=")
end
_master(settings)
_slaves(settings)
@settings = settings.dup
end

# Adds a new I18n locale file to the load path
Expand Down

0 comments on commit a04d568

Please sign in to comment.