/**1* Copyright 2013 Facebook, Inc.2*3* Licensed under the Apache License, Version 2.0 (the "License");4* you may not use this file except in compliance with the License.5* You may obtain a copy of the License at6*7* http://www.apache.org/licenses/LICENSE-2.08*9* Unless required by applicable law or agreed to in writing, software10* distributed under the License is distributed on an "AS IS" BASIS,11* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.12* See the License for the specific language governing permissions and13* limitations under the License.14*/15/*jslint proto:true*/1617var inherits = require('util').inherits;1819/**20* Base class for all Resource types21* Resource is a value object that holds the information about a particular22* resource. See properties.23*24* @abstract25* @class26* @param {String} path path of the resource27*/28var node_path = require('path');29function Resource(path) {30this.path = node_path.normalize(path);31this.id = node_path.normalize(path);32}3334Resource.prototype.mtime = 0;35Resource.prototype.type = 'Resource';3637/**38* Converts Resource to serializable object39* @return {Object}40*/41Resource.prototype.toObject = function() {42var object = { type: this.type };43for (var i in this) {44if (i.charAt(0) != '_' && this.hasOwnProperty(i)) {45object[i] = this[i];46}47}48return object;49};5051/**52* Creates a new resource from object53* @static54* @param {Object} object55* @return {Resource}56*/57Resource.fromObject = function(object) {58var type = this;59var instance = new type(object.path);60for (var i in object) {61instance[i] = object[i];62}63return instance;64};656667module.exports = Resource;686970