Method: MongoDelta::Configuration.load_from_db

Defined in:
lib/mongo_delta/configuration.rb

.load_from_db(mongodb_uri, db = nil, service = nil) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/mongo_delta/configuration.rb', line 18

def self.load_from_db(mongodb_uri, db=nil, service=nil)
  db ||= DEFAULT_DB
  service ||= DEFAULT_SERVICE

  mongo = connect_to_source(mongodb_uri)
  collection = mongo.db(db).collection('config')

  unless options = collection.find_one(:_id => service)
    raise Error, "There was no config in the database at #{mongodb_uri}/#{db} with id '#{service}'"
  end

  new(options.merge({'source' => mongo, 'db' => db, 'service' => service}))
end