/
FixtureConfig.js
74 lines (61 loc) · 2.33 KB
/
FixtureConfig.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/*
* A basic object to help handle organizing and interfacing with
* settings needed to make mongoose-fixture load things correctly.
*
*/
module.exports = function(params){
var that = {};
that.mongoConnection = params.mongoConnection;
/*
* When setting path check if base path is set, if not then assume paths set for schema/data-fixture is abs
* Returns a diction of
* basePath
* schemaPath
* dataFixturePath
*/
that.paths = function(paths){
var local = {};
// operations to check if base is set, if so then append it to all subpaths
// if not set then assume schema/data are set directly
if(paths.basePath === '' || paths.basePath === undefined){
// if base isn't defined then user has defined abs paths in each
local = paths;
// if basepath is a defined string
} else if(paths.basePath){
local.basePath = paths.basePath;
local.schemaPath = paths.basePath+paths.schemaPath;
local.dataFixturePath = paths.basePath+paths.dataFixturePath;
}
return local;
}(params.paths);
/*
* in charge of binding the fixtureListings into the config object based on the idicated key reference
*/
that.fixtureListings = function(){
var local={};
// going to store fixtures in this local key-obj store
local._fixtures = {};
local.set = function(key, fixtures){
// check if the fixture has paths set, if not use default paths
local._fixtures[key] = [];
var fixture = {};
for (var i in fixtures){
fixture = fixtures[i];
// going to set our global paths if none are defined for the fixture
if(fixture.schemaPath === undefined || fixture.schemaPath === ''){
fixture.schemaPath = that.paths.schemaPath;
}
if(fixture.dataFixturePath === undefined || fixture.dataFixturePath === ''){
fixture.dataFixturePath = that.paths.dataFixturePath;
}
// add fixture
local._fixtures[key].push(fixture);
}
};
local.get = function(key){
return local._fixtures[key];
};
return local;
}();
return that;
};