Skip to content

Commit

Permalink
addresses issue #14
Browse files Browse the repository at this point in the history
  • Loading branch information
emmanuel committed Aug 7, 2017
1 parent 139e4e1 commit 269e631
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 9 deletions.
6 changes: 3 additions & 3 deletions lib/fawn.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ var collection;
var TaskMdl;
var Task;
var Roller;
var utils;
var dbUtils;

var Fawn = {
init: function(db, _collection, options) {
Expand Down Expand Up @@ -41,7 +41,7 @@ var Fawn = {
TaskMdl = require("../models/task")(mongoose, collection);
Task = require("./task")(mongoose, TaskMdl);
Roller = require("./roller")(mongoose, TaskMdl);
utils = require("./utils/db.utils")(mongoose);
dbUtils = require("./utils/db.utils")(mongoose);
}

, Task: function() {
Expand All @@ -56,7 +56,7 @@ var Fawn = {

, initModel: function (modelName, schema) {
checkInitStatus();
utils.initModel(modelName, schema);
dbUtils.initModel(modelName, schema);
}
};

Expand Down
2 changes: 2 additions & 0 deletions lib/task.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ var TaskProvider = function (_mongoose, _TaskMdl) {
setModel = dbUtils.setModel;
getModel = dbUtils.getModel;

goose.setDbUtils(dbUtils);

return Task;
};

Expand Down
13 changes: 10 additions & 3 deletions lib/task_core/goose.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,26 @@
*/
var constants = require("../constants");
var utils = require("../utils/gen.utils");
var dbUtils = require("../utils/db.utils")();
var dbUtils;

// utility functions
// gen utility functions
var resolveFuture = utils.resolveFuture;
var storeOldData = utils.storeOldData;
var updateState = utils.updateState;
var xcode = utils.xcode;
var getModel = dbUtils.getModel;

// db utility functions
var getModel;

// constants
var PENDING = constants.PENDING;
var DONE = constants.DONE;

exports.setDbUtils = function (_dbUtils) {
dbUtils = _dbUtils;
getModel = dbUtils.getModel;
};

/**
* This function handles the update step using
* mongoose.
Expand Down
3 changes: 1 addition & 2 deletions lib/utils/db.utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ var constants = require("../constants");
var mongoose;

module.exports = function(_mongoose) {
if(!mongoose) mongoose = _mongoose || require("mongoose");

mongoose = _mongoose;
var Schema = mongoose.Schema;

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/all.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ global.mongoose = require("mongoose");
global.Grid = require("gridfs-stream");
Grid.mongo = mongoose.mongo;

global.dbUtils = require("../lib/utils/db.utils")();
global.dbUtils = require("../lib/utils/db.utils")(mongoose);
global.utils = require("../lib/utils/gen.utils");
global.expect = config.expect;
global.Promise = config.Promise;
Expand Down

0 comments on commit 269e631

Please sign in to comment.