Class: MongoMapper::ConnectionsPool

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

Overview

Connection Pool

Instance Method Summary collapse

Instance Method Details

#[](database_alias) ⇒ Object



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

def [](database_alias)
  database_alias = database_alias.to_s
  unless connection = super(database_alias)            
    raise "unknown database alias :#{database_alias}" unless MongoMapper.db_config.include? database_alias
    db_options = MongoMapper.db_config[database_alias]        
    connection = Mongo::Connection.new(db_options['host'], db_options['port'], logger: MongoMapper.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