Skip to content

Commit

Permalink
Merge pull request #18 from jenius/master
Browse files Browse the repository at this point in the history
'Pathes' is not a word
  • Loading branch information
samccone committed Jun 20, 2013
2 parents 4ddc9fe + ad30de2 commit 8ebb76c
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 33 deletions.
4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -59,8 +59,8 @@ Monocle.watchFiles({
Just an alias of `watchFiles` and `watchDirectory` so you don't need to tell if that's a file or a directory by yourself. Parameter passed to `path` can be a `string` or a `array` of `string`.

```js
Monocle.watchPathes({
path: [], //list of pathes, or a string of path
Monocle.watchPaths({
path: [], //list of paths, or a string of path
fileFilter: <optional>, // `*.js` for example
listener: <fn(fs.stat+ object)>, //triggered on file / addition
complete: <fn> //file watching all set up
Expand Down
18 changes: 9 additions & 9 deletions monocle.js
Expand Up @@ -134,16 +134,16 @@ module.exports = function() {
}
}

// distinguish be files and directories
// return am object of two arrays
// distinguish between files and directories
// @returns {Object} contains directories and files array

function distinguishPathes(pathes) {
pathes = Array.isArray(pathes) ? pathes : [pathes];
function distinguishPaths(paths) {
paths = Array.isArray(paths) ? paths : [paths];
var result = {
directories: [],
files: []
};
pathes.forEach(function(name) {
paths.forEach(function(name) {
if (fs.statSync(name).isDirectory()) {
result.directories.push(name);
} else {
Expand All @@ -166,9 +166,9 @@ module.exports = function() {
return object;
};

// watch files if the pathes refer to files, or directories
function watchPathes(args) {
var result = distinguishPathes(args.path)
// watch files if the paths refer to files, or directories
function watchPaths(args) {
var result = distinguishPaths(args.path)
if (result.directories.length) {
result.directories.forEach(function(directory) {
watchDirectory(extend(args, {root: directory}));
Expand All @@ -181,7 +181,7 @@ module.exports = function() {
return {
watchDirectory: watchDirectory,
watchFiles: watchFiles,
watchPathes: watchPathes,
watchPaths: watchPaths,
unwatchAll: unwatchAll
};
}
44 changes: 22 additions & 22 deletions test/tester.js
Expand Up @@ -47,7 +47,7 @@ describe("file changes", function() {
});

it("should detect a change", function(complete) {
monocle.watchPathes({
monocle.watchPaths({
path: sample_dir,
listener: function(f) { cb_helper('longbow.js', f, complete); },
complete: function() { complete_helper('/sample_files/longbow.js'); }
Expand Down Expand Up @@ -98,7 +98,7 @@ describe("file added", function() {
});

it("should detect another file added", function(complete) {
monocle.watchPathes({
monocle.watchPaths({
path: sample_dir,
listener: function(f) {
cb_helper("creation2.txt", f, complete);
Expand All @@ -110,7 +110,7 @@ describe("file added", function() {
});

it("should detect another file added but passed as list", function(complete) {
monocle.watchPathes({
monocle.watchPaths({
path: [sample_dir],
listener: function(f) {
cb_helper("creation2.txt", f, complete);
Expand Down Expand Up @@ -202,15 +202,15 @@ describe("files watched", function() {


//
// watch an array of pathes
// watch an array of paths
//
describe("pathes watched", function() {
describe("paths watched", function() {
it("should detect a file changed of multiple", function(complete) {
complete_helper('/sample_files/creation.txt');
complete_helper('/sample_files/creation2.txt');
complete_helper('/sample_files/creation3.txt');

monocle.watchPathes({
monocle.watchPaths({
path: [__dirname+"/sample_files/creation.txt", __dirname+"/sample_files/creation2.txt"],
listener: function(f) {
cb_helper("creation2.txt", f, complete)
Expand All @@ -223,7 +223,7 @@ describe("pathes watched", function() {

it("should detect a file changed (delayed)", function(complete) {
complete_helper('/sample_files/creation3.txt');
monocle.watchPathes({
monocle.watchPaths({
path: [__dirname+"/sample_files/creation3.txt"],
listener: function(f) {
setTimeout(function() {
Expand All @@ -238,7 +238,7 @@ describe("pathes watched", function() {

it("should detect a file changed (short delayed)", function(complete) {
complete_helper('/sample_files/creation4.txt');
monocle.watchPathes({
monocle.watchPaths({
path: [__dirname+"/sample_files/creation4.txt"],
listener: function(f) {
setTimeout(function() {
Expand All @@ -253,7 +253,7 @@ describe("pathes watched", function() {

it("should detect a file changed", function(complete) {
complete_helper('/sample_files/creation.txt');
monocle.watchPathes({
monocle.watchPaths({
path: [__dirname+"/sample_files/creation.txt"],
listener: function(f) {
cb_helper("creation.txt", f, complete)
Expand All @@ -266,7 +266,7 @@ describe("pathes watched", function() {

it("should not bomb when no callback is passed", function(complete) {
complete_helper('/sample_files/creation5.txt');
monocle.watchPathes({
monocle.watchPaths({
path: [__dirname+"/sample_files/creation5.txt"],
complete: function() {
complete_helper('/sample_files/creation5.txt');
Expand All @@ -279,13 +279,13 @@ describe("pathes watched", function() {
});

//
// watchPathes should be eager to accept string and arrays
// watchPaths should accept a string or an array
//

describe("different parameters of watchPathes", function() {
describe("different parameters of watchPaths", function() {

it("may be a file", function(complete) {
monocle.watchPathes({
it("can be a file", function(complete) {
monocle.watchPaths({
path: sample_dir + "/foo.txt",
listener: function(f) {
cb_helper("foo.txt", f, complete);
Expand All @@ -296,8 +296,8 @@ describe("different parameters of watchPathes", function() {
});
});

it("may be a string of a directory", function(complete) {
monocle.watchPathes({
it("can be a directory", function(complete) {
monocle.watchPaths({
path: sample_dir,
listener: function(f) {
cb_helper("foo.txt", f, complete);
Expand All @@ -308,8 +308,8 @@ describe("different parameters of watchPathes", function() {
});
});

it("may be a list of directories", function(complete) {
monocle.watchPathes({
it("can be a list of directories", function(complete) {
monocle.watchPaths({
path: [sample_dir],
listener: function(f) {
cb_helper("foo.txt", f, complete);
Expand All @@ -320,8 +320,8 @@ describe("different parameters of watchPathes", function() {
});
});

it("may be a list of directory and file", function(complete) {
monocle.watchPathes({
it("can be a list of directories and a file", function(complete) {
monocle.watchPaths({
path: [sample_dir + "/nestedDir", sample_dir + "/foo.txt"],
listener: function(f) {
cb_helper("foo.txt", f, complete);
Expand All @@ -332,8 +332,8 @@ describe("different parameters of watchPathes", function() {
});
});

it("may be a list of file and directory", function(complete) {
monocle.watchPathes({
it("can be a list of files and a directory", function(complete) {
monocle.watchPaths({
path: [sample_dir + "/foo.txt", sample_dir + "/nestedDir"],
listener: function(f) {
cb_helper("servent.txt", f, complete);
Expand Down

0 comments on commit 8ebb76c

Please sign in to comment.