Skip to content

Commit

Permalink
fix(env.js): handle rigth object arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
Julien Caré committed Nov 22, 2016
1 parent 61a3737 commit 46acb83
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
24 changes: 23 additions & 1 deletion src/lib/env.getOrElseAll.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,18 @@ describe('.getOrElseAll', function() {
ok: {
heyheyhey: true
}
}
},
exchanges: [
{
name: 'exchange.one',
type: 'topic',
durable: true
}, {
name: 'exchange.one.dead',
type: 'topic',
durable: true
}
]
},

a: {
Expand Down Expand Up @@ -108,6 +119,17 @@ describe('.getOrElseAll', function() {
t.strictEqual(config.AMQP.PLOP.ok.heyheyhey, true);
t.strictEqual(config.AMQP.connect, true);
t.strictEqual(config.AMQP.connect2, false);
t.deepEqual(config.AMQP.exchanges, [
{
name: 'exchange.one',
type: 'topic',
durable: true
}, {
name: 'exchange.one.dead',
type: 'topic',
durable: true
}
]);

t.deepEqual(config.a.b.c.f, ['a', 'c', 'd']);
t.deepEqual(config.a.b.c.fOverride, 'hello'.split(''));
Expand Down
4 changes: 3 additions & 1 deletion src/lib/env.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ module.exports = function envFactory() {
* @return {[type]} [description]
*/
function getMaxIndex(envKeyNamePrefix, env) {
return _.chain(env)
var envMaxIndex = _.chain(env)
.toPairs()
// only keep keys that are in the format {envKeyNamePrefix}__{NUMBER}[....] (because it can either be an array of array or an array of other objects)
.filter(([envKey, envVal], k) => {
Expand All @@ -105,6 +105,8 @@ module.exports = function envFactory() {
})
.max()
.value() || 0;

return Math.max(envMaxIndex, arrayValues.length - 1);
}

return _.range(0, getMaxIndex(context.fullKeyName, process.env) + 1).map(function(___, index) {
Expand Down

0 comments on commit 46acb83

Please sign in to comment.