Class: MongoMapper::DatabasesPool

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

Overview

Databases Pool

Instance Method Summary collapse

Instance Method Details

#[](database_alias) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/mongo_mapper_ext/mongo_mapper/plugins/db_config.rb', line 30

def [](database_alias)
  database_alias = database_alias.to_s
  unless db = super(database_alias)
    raise "unknown database alias :#{database_alias}" unless MongoMapper.db_config.include? database_alias
    db_options = MongoMapper.db_config[database_alias]
    name = db_options['name']
    raise "database name should be a string (#{name})!" unless name.is_a?(String)
    db = MongoMapper.connections[database_alias].db name
    self[database_alias] = db
  end
  return db
end