Module: Mddb::Config

Defined in:
lib/mddb/config.rb

Class Method Summary collapse

Class Method Details

.config=(file) ⇒ Object



11
12
13
14
15
16
17
18
19
# File 'lib/mddb/config.rb', line 11

def self.config=(file)
  config = YAML.load_file(file)
  config['database']['host'] = 'localhost' if config['database']['host'].nil?
  config['database']['port'] = 27017 if config['database']['port'].nil?
  raise "bad config file: database name needs to be defined" if config['database']['name'].nil?
  config['simulation']['dimensions'] = config['simulation']['dimensions'].split(',').collect {|a| a.to_f}
  @@config = config
  self.connect
end

.connectObject

The ranges of atoms in the config file are described as strings, we need to make them into ruby strings.



24
25
26
27
28
29
30
31
32
# File 'lib/mddb/config.rb', line 24

def self.connect
  host = Mddb::Config.database['host']
  database = Mddb::Config.database['name'] 
  MongoMapper.connection = Mongo::Connection.new(host)
  MongoMapper.database = database
  user = Mddb::Config.database['user']
  pass = Mddb::Config.database['pass']
  MongoMapper.database.authenticate(user,pass)
end

.databaseObject



3
4
5
# File 'lib/mddb/config.rb', line 3

def self.database
 @@config['database'] ||= {}
end

.simulationObject



7
8
9
# File 'lib/mddb/config.rb', line 7

def self.simulation
  @@config['simulation']
end