Skip to content

Commit

Permalink
add wildcard boolean support (#3)
Browse files Browse the repository at this point in the history
with *.bool_option syntax
  • Loading branch information
msimerson authored Oct 20, 2016
1 parent 5e78faf commit de951cb
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 16 deletions.
16 changes: 8 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
language: node_js
node_js:
- "4.3"
- "5.6"
- "4"
- "6"

before_script:
- npm install -g grunt-cli
# - npm install -g grunt-cli

script:
- grunt lint
- node run_tests
- npm run lint
- npm test

after_success:
- npm install istanbul codecov.io
- ./node_modules/istanbul/lib/cli.js cov run_tests
- cat ./coverage/coverage.json | ./node_modules/codecov.io/bin/codecov.io.js
- npm install istanbul codecov
- npm run coverage
- ./node_modules/.bin/codecov

sudo: false
10 changes: 6 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
"name": "haraka-config",
"license": "MIT",
"description": "Haraka's config file loader",
"version": "1.0.3",
"version": "1.0.4",
"homepage": "http://haraka.github.io",
"repository": {
"type": "git",
"url": "git@github.com:haraka/haraka-config.git"
},
"main": "config.js",
"engines": {
"node": ">= 0.10.43"
"node": ">= 0.12.16"
},
"dependencies": {
"js-yaml": "^3.5.3"
Expand Down Expand Up @@ -55,7 +55,7 @@
},
"optionalDependencies": {},
"devDependencies": {
"eslint": ">=2.0.0",
"eslint": ">=2",
"grunt": "*",
"grunt-eslint": "*",
"nodeunit": "^0.9.1"
Expand All @@ -65,6 +65,8 @@
"url": "https://github.com/haraka/haraka-config/issues"
},
"scripts": {
"test": "./run_tests"
"test": "./run_tests",
"lint": "./node_modules/.bin/grunt lint",
"coverage": "./node_modules/.bin/istanbul cov run_tests"
}
}
7 changes: 5 additions & 2 deletions readers/ini.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,11 @@ exports.load = function (name, options, regex) {
}

if (options && Array.isArray(options.booleans) &&
exports.bool_matches.indexOf(
current_sect_name + '.' + match[1]) !== -1) {
(
exports.bool_matches.indexOf(current_sect_name + '.' + match[1]) !== -1
||
exports.bool_matches.indexOf('*.' + match[1]) !== -1
)) {
current_sect[match[1]] = regex.is_truth.test(match[2]);
// var msg = 'Using boolean ' + current_sect[match[1]] +
// ' for ' + current_sect_name + '.' + match[1] + '=' + match[2];
Expand Down
4 changes: 3 additions & 1 deletion test/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,9 @@ exports.get = {
array_test: {
hostlist: [ 'first_host', 'second_host', 'third_host' ],
intlist: [ '123', '456', '789' ],
}
},
'foo.com': { is_bool: 'true' },
'bar.com': { is_bool: 'false' }
});
},

Expand Down
6 changes: 6 additions & 0 deletions test/config/test.ini
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,9 @@ hostlist[] = third_host
intlist[] = 123
intlist[] = 456
intlist[] = 789

[foo.com]
is_bool=true

[bar.com]
is_bool=false
13 changes: 12 additions & 1 deletion test/readers/ini.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ var regex = require('../../configfile').regex;

var _set_up = function (done) {
this.ini = require('../../readers/ini');
this.opts = { booleans: ['main.bool_true','main.bool_false'] };
this.opts = {
booleans: [ 'main.bool_true', 'main.bool_false' ]
};
done();
};

Expand Down Expand Up @@ -74,6 +76,15 @@ exports.load = {
test.strictEqual(r.sect1.bool_false_default, false);
test.done();
},
'test.ini, wildcard boolean' : function (test) {
test.expect(2);
var r = this.ini.load('test/config/test.ini', {
booleans: [ '*.is_bool' ]
}, regex);
test.strictEqual(r['foo.com'].is_bool, true);
test.strictEqual(r['bar.com'].is_bool, false);
test.done();
},
};

exports.empty = {
Expand Down

0 comments on commit de951cb

Please sign in to comment.