Skip to content

Commit

Permalink
optional array arg for specifying included siblings explicitly
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenhandley committed May 4, 2012
1 parent 3be4f66 commit ce0cb2f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 13 deletions.
30 changes: 19 additions & 11 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,30 @@
var fs = require('fs'),
path = require('path');

module.exports = function(dir) {
module.exports = function(dir, basenames) {
var requires = {};

fs.readdirSync(dir).forEach(function(filename) {
if (arguments.length == 1) {
fs.readdirSync(dir).forEach(function(filename) {

if ((filename === 'index.js') ||
(filename === 'index.coffee') ||
(filename[0] === '_')) {
return;
}
if ((filename === 'index.js') ||
(filename === 'index.coffee') ||
(filename[0] === '_')) {
return;
}

filename = path.basename(filename, path.extname(filename));
var filepath = path.join(dir, filename);
filename = path.basename(filename, path.extname(filename));
var filepath = path.join(dir, filename);

requires[filename] = require(filepath);
});
requires[filename] = require(filepath);
});

} else {
basenames.forEach(function(basename) {
var filepath = path.join(dir, basename)
requires[basename] = require(filepath);
});
}

return requires;
};
7 changes: 5 additions & 2 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,18 @@ try {
"definitely": lib.bar.fing,
"yes": lib.Foo.l,
"yep": lib.Foo.ls,
"ack": lib.bam.n
"ack": lib.bam.n,
"again": lib.bar.fed.again,
"somemore": lib.bar.fed.somemore
}

var keys = Object.keys(expectations)
keys.forEach(function(expectation) {
assert.equal(expectations[expectation](), expectation);
})

assert.equal('_private' in lib, false);
assert.equal(('_private' in lib), false);
assert.equal(('ignored' in lib.bar.fed), false);

console.log("All tests passed.");

Expand Down

0 comments on commit ce0cb2f

Please sign in to comment.