Class: MongoMapper::ConnectionsPool

Inherits:
Hash
  • Object
show all
Defined in:
lib/mongo_mapper_ext/db_config.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(mongo_mapper) ⇒ ConnectionsPool

Returns a new instance of ConnectionsPool.



4
5
6
# File 'lib/mongo_mapper_ext/db_config.rb', line 4

def initialize mongo_mapper
  self.mongo_mapper = mongo_mapper
end

Instance Attribute Details

#mongo_mapperObject

Returns the value of attribute mongo_mapper.



3
4
5
# File 'lib/mongo_mapper_ext/db_config.rb', line 3

def mongo_mapper
  @mongo_mapper
end

Instance Method Details

#[](database_alias) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/mongo_mapper_ext/db_config.rb', line 8

def [](database_alias)
  database_alias = database_alias.to_s
  unless connection = super(database_alias)            
    mongo_mapper.db_config.should! :include, database_alias
    db_options = mongo_mapper.db_config[database_alias]        
    connection = Mongo::Connection.new(db_options['host'], db_options['port'], :logger => mongo_mapper.logger)
  
    if defined?(PhusionPassenger)
      PhusionPassenger.on_event(:starting_worker_process) do |forked|
        connection.connect_to_master if forked
      end
    end
    
    self[database_alias] = connection
  end            
  return connection
end