Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
80669 views
1
/**
2
* Copyright 2013 Facebook, Inc.
3
*
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
* you may not use this file except in compliance with the License.
6
* You may obtain a copy of the License at
7
*
8
* http://www.apache.org/licenses/LICENSE-2.0
9
*
10
* Unless required by applicable law or agreed to in writing, software
11
* distributed under the License is distributed on an "AS IS" BASIS,
12
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
* See the License for the specific language governing permissions and
14
* limitations under the License.
15
*/
16
/*jslint proto:true*/
17
18
var inherits = require('util').inherits;
19
20
/**
21
* Base class for all Resource types
22
* Resource is a value object that holds the information about a particular
23
* resource. See properties.
24
*
25
* @abstract
26
* @class
27
* @param {String} path path of the resource
28
*/
29
var node_path = require('path');
30
function Resource(path) {
31
this.path = node_path.normalize(path);
32
this.id = node_path.normalize(path);
33
}
34
35
Resource.prototype.mtime = 0;
36
Resource.prototype.type = 'Resource';
37
38
/**
39
* Converts Resource to serializable object
40
* @return {Object}
41
*/
42
Resource.prototype.toObject = function() {
43
var object = { type: this.type };
44
for (var i in this) {
45
if (i.charAt(0) != '_' && this.hasOwnProperty(i)) {
46
object[i] = this[i];
47
}
48
}
49
return object;
50
};
51
52
/**
53
* Creates a new resource from object
54
* @static
55
* @param {Object} object
56
* @return {Resource}
57
*/
58
Resource.fromObject = function(object) {
59
var type = this;
60
var instance = new type(object.path);
61
for (var i in object) {
62
instance[i] = object[i];
63
}
64
return instance;
65
};
66
67
68
module.exports = Resource;
69
70