diff options
author | Samy Pesse <samypesse@gmail.com> | 2016-05-11 12:59:16 +0200 |
---|---|---|
committer | Samy Pesse <samypesse@gmail.com> | 2016-05-11 13:02:24 +0200 |
commit | d5c4af337795ca5c3d4e6f516aeaef15d51c4e8c (patch) | |
tree | 3c140ee30aadb820e07003ef4ab6f89d42323ae1 /lib/models/ignore.js | |
parent | 0b4df4cdf2dc9ed18805358216439b595997fdc7 (diff) | |
download | gitbook-d5c4af337795ca5c3d4e6f516aeaef15d51c4e8c.zip gitbook-d5c4af337795ca5c3d4e6f516aeaef15d51c4e8c.tar.gz gitbook-d5c4af337795ca5c3d4e6f516aeaef15d51c4e8c.tar.bz2 |
Add immutable ignore instance for book
Diffstat (limited to 'lib/models/ignore.js')
-rw-r--r-- | lib/models/ignore.js | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/lib/models/ignore.js b/lib/models/ignore.js new file mode 100644 index 0000000..499195e --- /dev/null +++ b/lib/models/ignore.js @@ -0,0 +1,42 @@ +var Immutable = require('immutable'); +var IgnoreMutable = require('ignore'); + +/* + Immutable version of node-ignore +*/ +var Ignore = Immutable.Record({ + ignore: new IgnoreMutable() +}, 'Ignore'); + +Ignore.prototype.getIgnore = function() { + return this.get('ignore'); +}; + +/** + Test if a file is ignored by these rules + + @param {String} filePath + @return {Boolean} +*/ +Ignore.prototype.isFileIgnored = function(filename) { + var ignore = this.getIgnore(); + return ignore.filter([filename]).length == 0; +}; + +/** + Add rules + + @param {String} + @return {Ignore} +*/ +Ignore.prototype.add = function(rule) { + var ignore = this.getIgnore(); + var newIgnore = new IgnoreMutable(); + + newIgnore.add(ignore); + newIgnore.add(rule); + + return this.set('ignore', newIgnore); +}; + +module.exports = Ignore; |