2014-05-07 10:10:59 -05:00
|
|
|
var fs = require('fs')
|
|
|
|
, listFilePath = './local-list.json';
|
2014-05-06 17:40:21 -05:00
|
|
|
|
|
|
|
var LocalList = function() {
|
|
|
|
if(fs.existsSync(listFilePath)) {
|
|
|
|
this.list = JSON.parse(fs.readFileSync(listFilePath, 'utf8'));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
this.list = [];
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
LocalList.prototype = {
|
|
|
|
add: function(name) {
|
|
|
|
if(this.list.indexOf(name) == -1) {
|
|
|
|
this.list.push(name);
|
|
|
|
this.sync();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
remove: function() {
|
|
|
|
var i = this.list.indexOf(name);
|
|
|
|
if(i != -1) {
|
|
|
|
this.list.splice(i, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
this.sync();
|
|
|
|
},
|
|
|
|
get: function() {
|
|
|
|
return this.list;
|
|
|
|
},
|
|
|
|
sync: function() {
|
2014-05-08 11:13:39 -05:00
|
|
|
fs.writeFileSync(listFilePath, JSON.stringify(this.list)); //Uses sync to prevent ugly race condition
|
2014-05-06 17:40:21 -05:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = new LocalList();
|