-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathschema.js
More file actions
59 lines (59 loc) · 2.06 KB
/
schema.js
File metadata and controls
59 lines (59 loc) · 2.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
var fs = require('fs');
var TimelineClass = require('./timeline');
// Represents a group of several time lines
module.exports = function (storage, name) {
// The storage holding the current schema
this._storage = storage;
// Name of the given schema
this._name = name;
// Creates a new time line in the current schema
this.create = function (timelineName, callback) {
var path = this._storage._path + '/' + this._name + '/' + timelineName;
fs.exists(path, function (exists) {
if (exists) {
callback();
} else {
fs.writeFile(path, '', function (error) {
if (error) {
callback(error);
return;
}
callback();
});
}
});
};
// Lists all schema's time lines
this.list = function (callback) {
var self = this;
var path = this._storage._path + '/' + this._name;
fs.readdir(path, function (error, fileNames) {
if (undefined != error) {
callback(error);
return;
}
var timeLines = [];
for (var i = 0; i < fileNames.length; i++) {
var fileName = fileNames[i];
var timeLine = new TimelineClass(self, fileName);
timeLines.push(timeLine);
}
callback(undefined, timeLines);
});
};
// Gets a time line from the current schema specified by the time line name
this.get = function (timelineName) {
var timeline = new TimelineClass(this, timelineName);
return timeline;
};
this.remove = function (timelineName, callback) {
var path = this._storage._path + '/' + this._name + '/' + timelineName;
fs.unlink(path, function (error) {
if (undefined != error) {
callback(error);
return;
}
callback();
});
}
};