Skip to content

Commit

Permalink
Implemented a part of the PhysicalFSManager
Browse files Browse the repository at this point in the history
  • Loading branch information
AdrienCastex committed May 12, 2017
1 parent 9c9a3bc commit 9cf0b9f
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 0 deletions.
13 changes: 13 additions & 0 deletions lib/manager/PhysicalFSManager.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { PhysicalResource } from '../resource/PhysicalResource';
import { IResource, ResourceType } from '../resource/Resource';
import { FSManager } from './FSManager';
export declare class PhysicalFSManager implements FSManager {
private static _instance;
static instance(): PhysicalFSManager;
serialize(resource: any): object;
unserialize(serializedResource: {
realPath: string;
isFile: boolean;
}): PhysicalResource;
newResource(fullPath: string, name: string, type: ResourceType, parent: IResource): IResource;
}
31 changes: 31 additions & 0 deletions lib/manager/PhysicalFSManager.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var PhysicalResource_1 = require("../resource/PhysicalResource");
var PhysicalFSManager = (function () {
function PhysicalFSManager() {
}
PhysicalFSManager.instance = function () {
if (!this._instance)
this._instance = new PhysicalFSManager();
return this._instance;
};
PhysicalFSManager.prototype.serialize = function (resource) {
if (!resource.realPath)
throw new Error('Unrocognized resource');
return { realPath: resource.realPath, isFile: resource.constructor === PhysicalResource_1.PhysicalFile };
};
PhysicalFSManager.prototype.unserialize = function (serializedResource) {
if (serializedResource.realPath) {
if (serializedResource.isFile)
return new PhysicalResource_1.PhysicalFile(serializedResource.realPath, null, this);
else
return new PhysicalResource_1.PhysicalFolder(serializedResource.realPath, null, this);
}
throw new Error('Unrocognized resource');
};
PhysicalFSManager.prototype.newResource = function (fullPath, name, type, parent) {
throw new Error('Not implemented yet');
};
return PhysicalFSManager;
}());
exports.PhysicalFSManager = PhysicalFSManager;
39 changes: 39 additions & 0 deletions src/manager/PhysicalFSManager.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { PhysicalFile, PhysicalFolder, PhysicalResource } from '../resource/PhysicalResource'
import { IResource, ResourceType } from '../resource/Resource'
import { FSManager } from './FSManager'

export class PhysicalFSManager implements FSManager
{
private static _instance : PhysicalFSManager;
static instance()
{
if(!this._instance)
this._instance = new PhysicalFSManager();
return this._instance;
}

serialize(resource : any) : object
{
if(!resource.realPath)
throw new Error('Unrocognized resource');

return { realPath: resource.realPath, isFile: resource.constructor === PhysicalFile };
}
unserialize(serializedResource : { realPath : string, isFile : boolean }) : PhysicalResource
{
if(serializedResource.realPath)
{
if(serializedResource.isFile)
return new PhysicalFile(serializedResource.realPath, null, this);
else
return new PhysicalFolder(serializedResource.realPath, null, this);
}

throw new Error('Unrocognized resource');
}

newResource(fullPath : string, name : string, type : ResourceType, parent : IResource) : IResource
{
throw new Error('Not implemented yet');
}
}

0 comments on commit 9cf0b9f

Please sign in to comment.