Skip to content

Commit

Permalink
strict by default
Browse files Browse the repository at this point in the history
  • Loading branch information
drewfish committed Sep 9, 2014
1 parent 893a30b commit 4073e59
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
9 changes: 5 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ function replacer(base) {
* @contructor
* @param bundle {array} array of bundle parts
* @param options {object}
* @param options.strictDimensions {bool} whether unknown dimensions in the settings should be ignored
* @param options.lenientDimensions {bool} whether unknown dimensions in the settings should be applied to "master"
*/
function Ycb(bundle, options) {
this.options = options || {};
Expand Down Expand Up @@ -456,13 +456,14 @@ Ycb.prototype = {
}
}
if (!lookup[name]) {
if (options.strictDimensions) {
if (!context.hasOwnProperty(name) || options.lenientDimensions) {
lookup[name] = DEFAULT;
}
else {
console.log('invalid value for dimension "' + name +
'" in settings ' + JSON.stringify(settings));
return undefined;
}
// be lenient and act as if the dimension wasn't specified
lookup[name] = DEFAULT;
}
}
}
Expand Down
22 changes: 18 additions & 4 deletions tests/unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -536,23 +536,37 @@ cases = {
}, config);
},

'unknown dimensions and options.strictDimensions': function() {
'test options.lenientDimensions': function() {
var bundle,
ycb,
config;

bundle = readFixtureFile('dimensions.json')
bundle = readFixtureFile('dimensions.json');
bundle.push({
settings: ['master'],
appPort: 80
});
bundle.push({
settings: ['environment:stage'],
settings: ['environment:lkjsdflksdhlskdfs'],
appPort: 81
});
ycb = new libycb.Ycb(bundle, {strictDimensions: true});
ycb = new libycb.Ycb(bundle);
config = ycb.read({});
A.areSame(80, config.appPort);

bundle = readFixtureFile('dimensions.json');
bundle.push({
settings: ['master'],
appPort: 80
});
bundle.push({
settings: ['environment:lkjsdflksdhlskdfs'],
appPort: 81
});
ycb = new libycb.Ycb(bundle, {lenientDimensions: true});
config = ycb.read({});
A.areSame(81, config.appPort);

}

};
Expand Down

0 comments on commit 4073e59

Please sign in to comment.