Navigation Menu

Skip to content

Commit

Permalink
expose abstract interface
Browse files Browse the repository at this point in the history
  • Loading branch information
Carreau committed Jun 2, 2015
1 parent 39f59e4 commit 5f0c610
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 37 deletions.
3 changes: 2 additions & 1 deletion jupyterdrive/gdrive/drive-contents.d.ts
@@ -1,4 +1,5 @@
export declare class Contents {
import iface = require('content-interface');
export declare class Contents implements iface.IContents {
base_url: string;
config: any;
last_observed_revision: any;
Expand Down
17 changes: 7 additions & 10 deletions jupyterdrive/gdrive/mixed-contents.d.ts
@@ -1,10 +1,11 @@
import iface = require('content-interface');
export interface File {
path: string;
}
export interface FileList {
contents: any;
}
export declare class Contents {
export declare class Contents implements iface.IContents {
config: any;
filesystem: any;
constructor(options: any);
Expand All @@ -13,11 +14,7 @@ export declare class Contents {
* @param {Object} filesystem
* @return {Object} An object representing a virtual directory.
*/
virtual_fs_roots(filesystem: any): {
type: string;
name: string;
path: string;
}[];
private _virtual_fs_roots(filesystem);
/**
* Routing functions
*/
Expand Down Expand Up @@ -45,24 +42,24 @@ export declare class Contents {
* @return {String} the converted path
*
*/
to_virtual_path(root: string, path: string): string;
private _to_virtual_path(root, path);
/**
* Takes a file model, and convert its path to the virtual filesystem.
* from Google Drive format
* @param {String} root The root of the virtual mount point.
* @param {File} file The file model (this is modified by the function).
* @return {File} the converted file model
*/
to_virtual_file(root: string, file: File): File;
private _to_virtual_file(root, file);
/**
* Takes a file list, and convert its path to the virtual filesystem.
* from Google Drive format
* @param {String} root The root of the virtual mount point.
* @param {Object} list The file list (this is modified by the function).
* @return {Object} The converted file list
*/
to_virtual_list(root: string, list: FileList): FileList;
to_virtual(root: string, type: any, object: any): any;
private _to_virtual_list(root, list);
private _to_virtual(root, type, object);
from_virtual(root: string, type: any, object: any, config: any): any;
/**
* Route a function to the appropriate content manager class
Expand Down
24 changes: 12 additions & 12 deletions jupyterdrive/gdrive/mixed-contents.js
Expand Up @@ -65,7 +65,7 @@ define(["require", "exports", 'jquery', "base/js/utils"], function (require, exp
* @param {Object} filesystem
* @return {Object} An object representing a virtual directory.
*/
Contents.prototype.virtual_fs_roots = function (filesystem) {
Contents.prototype._virtual_fs_roots = function (filesystem) {
return Object.keys(filesystem).map(function (root) {
return {
type: 'directory',
Expand Down Expand Up @@ -118,7 +118,7 @@ define(["require", "exports", 'jquery', "base/js/utils"], function (require, exp
* @return {String} the converted path
*
*/
Contents.prototype.to_virtual_path = function (root, path) {
Contents.prototype._to_virtual_path = function (root, path) {
return utils.url_path_join(root, path);
};
/**
Expand All @@ -128,8 +128,8 @@ define(["require", "exports", 'jquery', "base/js/utils"], function (require, exp
* @param {File} file The file model (this is modified by the function).
* @return {File} the converted file model
*/
Contents.prototype.to_virtual_file = function (root, file) {
file['path'] = this.to_virtual_path(root, file['path']);
Contents.prototype._to_virtual_file = function (root, file) {
file['path'] = this._to_virtual_path(root, file['path']);
return file;
};
/**
Expand All @@ -139,19 +139,19 @@ define(["require", "exports", 'jquery', "base/js/utils"], function (require, exp
* @param {Object} list The file list (this is modified by the function).
* @return {Object} The converted file list
*/
Contents.prototype.to_virtual_list = function (root, list) {
list['content'].forEach($.proxy(this.to_virtual_file, this, root));
Contents.prototype._to_virtual_list = function (root, list) {
list['content'].forEach($.proxy(this._to_virtual_file, this, root));
return list;
};
Contents.prototype.to_virtual = function (root, type, object) {
Contents.prototype._to_virtual = function (root, type, object) {
if (type === ArgType.PATH) {
return this.to_virtual_path(root, object);
return this._to_virtual_path(root, object);
}
else if (type === ArgType.FILE) {
return this.to_virtual_file(root, object);
return this._to_virtual_file(root, object);
}
else if (type === ArgType.LIST) {
return this.to_virtual_list(root, object);
return this._to_virtual_list(root, object);
}
else {
return object;
Expand Down Expand Up @@ -187,7 +187,7 @@ define(["require", "exports", 'jquery', "base/js/utils"], function (require, exp
var root = _this.get_fs_root(filesystem, args[0]);
if (root === '') {
if (method_name === 'list_contents') {
return { 'content': _this.virtual_fs_roots(filesystem) };
return { 'content': _this._virtual_fs_roots(filesystem) };
}
else {
throw 'true root directory only contains mount points.';
Expand All @@ -197,7 +197,7 @@ define(["require", "exports", 'jquery', "base/js/utils"], function (require, exp
args[i] = _this.from_virtual(root, arg_types[i], args[i], _this.config.data['mixed_contents']['schema']);
}
var contents = filesystem[root];
return contents[method_name].apply(contents, args).then($.proxy(_this.to_virtual, _this, root, return_type));
return contents[method_name].apply(contents, args).then($.proxy(_this._to_virtual, _this, root, return_type));
});
};
/**
Expand Down
16 changes: 16 additions & 0 deletions jupyterdrive/ts/content-interface.ts
@@ -0,0 +1,16 @@

/**
* Interface that a content manager should implement
**/
export interface IContents {
get(path, type, options):any
new_untitled
delete
rename
save
list_contents
copy
create_checkpoint
restore_checkpoint
list_checkpoints
}
5 changes: 4 additions & 1 deletion jupyterdrive/ts/drive-contents.ts
Expand Up @@ -7,6 +7,9 @@ import dialog = require('base/js/dialog');
import gapiutils = require('./gapiutils');
import driveutils = require('./driveutils');
import notebook_model = require('./notebook_model');
import iface = require('content-interface');



declare var gapi;

Expand Down Expand Up @@ -98,7 +101,7 @@ var files_resource_to_contents_model = function(path, resource, content?) {
};
};

export class Contents {
export class Contents implements iface.IContents {

base_url:string;
config:any;
Expand Down
27 changes: 14 additions & 13 deletions jupyterdrive/ts/mixed-contents.ts
Expand Up @@ -10,6 +10,7 @@ import IPython = require('base/js/namespace')

import utils = require("base/js/utils");
import Promises = require('es6-promise');
import iface = require('content-interface');

/** Enum for object types */
var ArgType = {
Expand Down Expand Up @@ -43,7 +44,7 @@ export interface FileList {
contents:any
}

export class Contents {
export class Contents implements iface.IContents {

config:any;
filesystem:any;
Expand Down Expand Up @@ -96,7 +97,7 @@ export class Contents {
* @param {Object} filesystem
* @return {Object} An object representing a virtual directory.
*/
virtual_fs_roots(filesystem) {
private _virtual_fs_roots(filesystem) {
return Object.keys(filesystem).map(function(root) {
return {
type: 'directory',
Expand Down Expand Up @@ -151,7 +152,7 @@ export class Contents {
* @return {String} the converted path
*
*/
to_virtual_path(root:string, path:string):string {
private _to_virtual_path(root:string, path:string):string {
return utils.url_path_join(root, path);
}

Expand All @@ -162,8 +163,8 @@ export class Contents {
* @param {File} file The file model (this is modified by the function).
* @return {File} the converted file model
*/
to_virtual_file(root:string, file:File):File {
file['path'] = this.to_virtual_path(root, file['path']);
private _to_virtual_file(root:string, file:File):File {
file['path'] = this._to_virtual_path(root, file['path']);
return file;
}

Expand All @@ -174,19 +175,19 @@ export class Contents {
* @param {Object} list The file list (this is modified by the function).
* @return {Object} The converted file list
*/
to_virtual_list(root:string, list:FileList):FileList {
list['content'].forEach($.proxy(this.to_virtual_file, this, root));
private _to_virtual_list(root:string, list:FileList):FileList {
list['content'].forEach($.proxy(this._to_virtual_file, this, root));
return list;
}


to_virtual(root:string, type, object) {
private _to_virtual(root:string, type, object) {
if (type === ArgType.PATH) {
return this.to_virtual_path(root, object);
return this._to_virtual_path(root, object);
} else if (type === ArgType.FILE) {
return this.to_virtual_file(root, object);
return this._to_virtual_file(root, object);
} else if (type === ArgType.LIST) {
return this.to_virtual_list(root, object);
return this._to_virtual_list(root, object);
} else {
return object;
}
Expand Down Expand Up @@ -221,7 +222,7 @@ export class Contents {

if (root === '') {
if (method_name === 'list_contents') {
return {'content': this.virtual_fs_roots(filesystem)};
return {'content': this._virtual_fs_roots(filesystem)};
} else {
throw 'true root directory only contains mount points.';
}
Expand All @@ -232,7 +233,7 @@ export class Contents {
}
var contents = filesystem[root];
return contents[method_name].apply(contents, args).then(
$.proxy(this.to_virtual, this, root, return_type));
$.proxy(this._to_virtual, this, root, return_type));
});
}

Expand Down

0 comments on commit 5f0c610

Please sign in to comment.