Skip to content

Commit

Permalink
Merge pull request #25 from namshi/follow-params
Browse files Browse the repository at this point in the history
Enhancing params resolution
  • Loading branch information
unlucio committed Mar 2, 2016
2 parents ac2dc03 + e6a6d63 commit 866e7b9
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
4 changes: 3 additions & 1 deletion reconfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,9 @@ Reconfig.prototype.resolveReferences = function(value) {
*/
Reconfig.prototype.resolveParameters = function(value, parameters) {
for (var property in parameters) {
value = (value) ? value.replace(':' + property, (parameters[property] || '')) : value;
if (value) {
value = value.replace(RegExp(':' + property, 'g'), (parameters[property] || ''));
}
}

return value;
Expand Down
18 changes: 18 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
var rec = require('./reconfig.js');
var c = {
root: {
a: 'valA',
b: {
c: '{{ root.a }}',
d: 'valD:paramD'
},
e: 'valE:paramE',
f: 'valeF {{root.b.d}}'
}
};

var conf = new rec(c);

console.log('conf: ', conf);
console.log('conf paramD: ', conf.get('root', {paramD: 'ddddddddddd'}));
console.log('conf app params: ', conf.get('root', {paramD: 'ddddddddddd', paramE: 'eeeeeeeeeeeeeeee'}));
14 changes: 14 additions & 0 deletions test/reconfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,20 @@ describe('Reconfig', function() {
}));
});

it('should be able to render parmas in composite values', function() {
var values = {
a: {
b: 'hello :what!'
},
c: '{{ a.b }}, :what'
};
var config = new reconfig(values);

assert('hello world!, world' === config.get('c', {
what: 'world'
}));
});

it('should be able to handle self-referencing configs', function() {
var values = {
a: {
Expand Down

0 comments on commit 866e7b9

Please # to comment.