Permalink
Browse files

add the option to pass config JSON objects to drivers

Signed-off-by: Tomas Neme <lacrymology@gmail.com>
  • Loading branch information...
Lacrymology committed Apr 5, 2013
1 parent da60f64 commit 504ba835b769d6c8e1355fec07cfaf383255eebb
Showing with 12 additions and 12 deletions.
  1. +1 −1 drivers/playlists/db.js
  2. +6 −6 drivers/playlists/mongo-driver.js
  3. +5 −5 drivers/playlists/playlists-driver.js
View
@@ -1,5 +1,5 @@
var db;
-exports.db = function() {
+exports.db = function(config) {
//var conf = require('config').MediaDB;
var conf = {
dbName: "mediadb",
@@ -4,11 +4,6 @@ var config = require("./conf/mongo-driver"),
mubsub = require("mubsub"),
moment = require("moment");
-var db = require('./db').db();
-var client = mubsub(db);
-
-var channel = client.channel('messages', { size: 10000000, max: 5000 });
-
function mongo_driver() {
var self = this;
@@ -18,7 +13,12 @@ function mongo_driver() {
console.log("mbc-mosto: [INFO] Creating mongodb playlists driver");
- mongo_driver.prototype.start = function() {
+ mongo_driver.prototype.start = function(config) {
+ var db = require('./db').db(config && config.db);
+ var client = mubsub(db);
+
+ var channel = client.channel('messages', { size: 10000000, max: 5000 });
+
self.scheds = db.collection('scheds');
self.lists = db.collection('lists');
self.readPlaylists();
@@ -1,7 +1,7 @@
var json_driver = require("./json-driver"),
mongo_driver = require("./mongo-driver");
-function playlists_driver(type) {
+function playlists_driver(type, config) {
var self = this;
this.driver = undefined;
@@ -12,9 +12,9 @@ function playlists_driver(type) {
console.log("mbc-mosto: [INFO] Creating playlists driver for type [" + type + "]");
if (type === 'json') {
- this.driver = new json_driver();
+ this.driver = new json_driver(config);
} else if (type === 'mongo') {
- this.driver = new mongo_driver();
+ this.driver = new mongo_driver(config);
} else {
var err = new Error("mbc-mosto: [ERROR] Unknown type of driver [" + type + "]");
console.error(err);
@@ -50,7 +50,7 @@ function playlists_driver(type) {
}
-exports = module.exports = function(type) {
- var driver = new playlists_driver(type);
+exports = module.exports = function(type, config) {
+ var driver = new playlists_driver(type, config);
return driver;
};

0 comments on commit 504ba83

Please sign in to comment.