Skip to content

Commit

Permalink
fixes arrays being incorrectly mapped k/v
Browse files Browse the repository at this point in the history
  • Loading branch information
okor committed Mar 20, 2015
1 parent 68058b3 commit e10deaf
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 30 deletions.
26 changes: 2 additions & 24 deletions lib/node-yaml-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,36 +12,14 @@
var fs = require('fs');
var path = require('path');
var yaml = require('js-yaml');
var extend = require('node.extend');

/**
* Hash of loaded files
*/

var loaded_files = {};

/**
* Merges properties found in `extension` into `doc`
*/

function merge(doc, extension) {
var prop;

for (prop in extension) {
if (extension.hasOwnProperty(prop)) {
if (extension[prop] instanceof Object) {
if (!doc.hasOwnProperty(prop)) {
doc[prop] = {};
}
merge(doc[prop], extension[prop]);
} else {
doc[prop] = extension[prop];
}
}
}

return doc;
}

/**
* Reads a yaml configuration file
*/
Expand Down Expand Up @@ -75,7 +53,7 @@ function load(filename, env) {
default_config = data.default || {};
extension_config = data[env] || {};

return merge(merge({}, default_config), extension_config);
return extend(true, extend(true, {}, default_config), extension_config);
}

/**
Expand Down
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
"version": "0.0.2",
"main": "./lib/node-yaml-config",
"dependencies": {
"js-yaml": "1.0.2"
"merge": "~1.2.0",
"js-yaml": "1.0.2",
"node.extend": "~1.1.3"
},
"directories": {
"example": "examples",
Expand All @@ -15,7 +17,7 @@
"should": "~1.2.0"
},
"scripts": {
"prepublish" : "npm prune",
"prepublish": "npm prune",
"test": "make test"
},
"repository": {
Expand Down
4 changes: 4 additions & 0 deletions test/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,7 @@ production:
password: 'pass'
cache:
dir: 'static'
admins:
- "humans"
- "subhumans"
- "arachnids"
9 changes: 5 additions & 4 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ var save_file = __dirname + '/config.yml.bak';
var new_file = __dirname + '/config-reload.yml';

var example_dev_config = {
server: {
server: {
port: 3000
},
database: {
Expand All @@ -19,7 +19,7 @@ var example_dev_config = {
};

var example_test_config = {
server: {
server: {
port: 3000
},
database: {
Expand All @@ -30,7 +30,7 @@ var example_test_config = {
};

var example_prod_config = {
server: {
server: {
port: 8000
},
database: {
Expand All @@ -42,7 +42,8 @@ var example_prod_config = {
},
cache: {
dir: 'static'
}
},
admins: [ "humans", "subhumans", "arachnids" ]
};

var example_new_dev_config = {
Expand Down

0 comments on commit e10deaf

Please sign in to comment.