Skip to content

Commit

Permalink
pulling 'walk' method from utils
Browse files Browse the repository at this point in the history
  • Loading branch information
Joseph (Jos) Smith committed May 27, 2013
1 parent 7632000 commit 2057e92
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 39 deletions.
27 changes: 0 additions & 27 deletions server/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,33 +19,6 @@ utils.isErrorStatus = function(statusCode, options) {
}
};

// http://stackoverflow.com/q/5827612/
utils.walk = function(dir, callback) {
var results = [];

fs.readdir(dir, function(err, list) {
if (err) return callback(err);

var pending = list.length;
if (!pending) return callback(null, results);

list.forEach(function(file) {
file = dir + '/' + file;
fs.stat(file, function(err, stat) {
if (stat && stat.isDirectory()) {
utils.walk(file, function(err, res) {
results = results.concat(res);
if (!--pending) { callback(null, results); }
});
} else {
results.push(file);
if (!--pending) { callback(null, results); }
}
});
});
});
};

utils.getApiHost = function(path, apiHostsMap) {
var extractParamNamesRe = /:(\w+)/g,
apiHost = null,
Expand Down
12 changes: 0 additions & 12 deletions test/server/utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,6 @@ var _ = require('underscore'),

describe('utils', function() {

describe('walk', function() {
it('should return an array of a given directory\'s filenames', function(done) {
var nodeNames = [],
walkableDir = path.resolve(__dirname+'/../fixtures/walkableDir');

utils.walk(walkableDir, function(err, names) {
names.should.be.an.instanceOf(Array).with.lengthOf(6);
done(err);
});
});
});

describe('getApiHost', function() {
beforeEach(function() {
this.apiHostsMap = {
Expand Down

0 comments on commit 2057e92

Please sign in to comment.