2014-10-23 13:51:37 +02:00
|
|
|
var Promise = require("bluebird");
|
2014-12-10 18:45:02 +01:00
|
|
|
var NotFoundError = require('../lib/error/NotFoundError');
|
2014-10-23 13:51:37 +02:00
|
|
|
|
|
|
|
var features = [
|
|
|
|
{
|
|
|
|
"name": "featureX",
|
|
|
|
"description": "the #1 feature",
|
|
|
|
"enabled": true,
|
|
|
|
"strategy": "default"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"name": "featureY",
|
|
|
|
"description": "soon to be the #1 feature",
|
|
|
|
"enabled": false,
|
|
|
|
"strategy": "baz",
|
|
|
|
"parameters": {
|
|
|
|
"foo": "bar"
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"name": "featureZ",
|
|
|
|
"description": "terrible feature",
|
|
|
|
"enabled": true,
|
|
|
|
"strategy": "baz",
|
|
|
|
"parameters": {
|
|
|
|
"foo": "rab"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
2014-10-23 15:17:04 +02:00
|
|
|
function getFeature(name) {
|
|
|
|
var featureFound;
|
|
|
|
features.forEach(function (feature) {
|
|
|
|
if (feature.name === name) {
|
|
|
|
featureFound = feature;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return featureFound;
|
|
|
|
}
|
|
|
|
|
2014-10-23 13:51:37 +02:00
|
|
|
module.exports = {
|
|
|
|
getFeatures: function() {
|
|
|
|
return new Promise(function (resolve) {
|
|
|
|
resolve(features);
|
|
|
|
});
|
2014-10-23 15:17:04 +02:00
|
|
|
},
|
|
|
|
getFeature: function(name) {
|
|
|
|
var feature = getFeature(name);
|
|
|
|
if(feature) {
|
|
|
|
return Promise.resolve(feature);
|
|
|
|
} else {
|
2014-12-10 18:45:02 +01:00
|
|
|
return Promise.reject(new NotFoundError("feature not found"));
|
2014-10-23 15:17:04 +02:00
|
|
|
}
|
2014-10-23 13:51:37 +02:00
|
|
|
}
|
|
|
|
};
|