Skip to content

Commit

Permalink
Generate API doc
Browse files Browse the repository at this point in the history
  • Loading branch information
dundalek committed Oct 6, 2013
1 parent 95fd82d commit d5a964a
Show file tree
Hide file tree
Showing 55 changed files with 16,111 additions and 124 deletions.
40 changes: 28 additions & 12 deletions backend/base.js
@@ -1,4 +1,5 @@

/** @module base */
(function (factory) {
if (typeof module !== 'undefined' && typeof module.exports !== 'undefined' && typeof require !== 'undefined') {
// CommonJS
Expand All @@ -18,28 +19,32 @@ function BaseBackend() {
_.extend(BaseBackend.prototype,
/** @lends BaseBackend# */
{
/** */
/** Initialize the backend instance */
initialize: function(options) {
options = _.extend({}, options || {});
this.options = options;
},

/** */
/** List storage names (e.g. tables for SQL, collections for MongoDB)
@abstract */
objectStoreNames: function() {

},

/** */
/** Get object store
* @abstract */
objectStore: function(name, options) {

},

/** */
/** Create object store
@abstract */
createObjectStore: function(name, options) {

},

/** */
/** Delete object store
@abstract */
deleteObjectStore: function(name) {

}
Expand All @@ -55,7 +60,8 @@ function BaseStore() {
_.extend(BaseStore.prototype,
/** @lends BaseStore# */
{
/** */
/** Initialize the backend instance
@constructs */
initialize: function(backend, name, options) {
options = _.extend({keyPath: 'id'}, options || {});
this.options = options;
Expand All @@ -65,36 +71,44 @@ _.extend(BaseStore.prototype,
this.keyPath = this.options.keyPath;
},

/** */
/** Get value (aka READ)
@abstract */
get: function(directives) {

},

/** */
/** Add value (aka CREATE, insert)
@abstract */
add: function(object, directives) {

},

/** */
/** Get value (aka UPDATE)
@abstract */
put: function(object, directives) {

},

/** */
/** Delete value (aka DELETE)
@abstract */
'delete': function(directives) {

},

/** Execute RQL query */
/** Execute RQL query
@abstract */
query: function(query) {

},

/** Delete all items */
/** Delete all items
@abstract */
clear: function() {

},

/** Extract key value from object
@private */
_getObjectKey: function(obj, key) {
if (typeof key === 'object') {
key = key.key;
Expand Down Expand Up @@ -154,8 +168,10 @@ _.extend(BaseStore.prototype,
return child;
};

/** Class inheritance */
BaseStore.extend = extend;

/** Class inheritance */
BaseBackend.extend = extend;
BaseBackend.BaseStore = BaseStore;

Expand Down
27 changes: 15 additions & 12 deletions backend/elasticsearch.js
@@ -1,4 +1,5 @@

/** @module elasticsearch */
(function (factory) {
var ajax, Q;
if (typeof module !== 'undefined' && typeof module.exports !== 'undefined' && typeof require !== 'undefined') {
Expand Down Expand Up @@ -37,11 +38,12 @@
}
})(function(ajax, _, BaseBackend, rql2es) {

/** @class ElasticSearchBackend */
/** @class ElasticSearchBackend
@extends BaseBackend */
var ElasticSearchBackend = BaseBackend.extend(
/** @lends ElasticSearchBackend# */
{
/** */
/** @method */
initialize: function(options) {
options = _.extend({url: '/'}, options || {});
options.url = options.url.replace(/\/?$/, '/');
Expand All @@ -50,25 +52,25 @@ var ElasticSearchBackend = BaseBackend.extend(
this.url = options.url;
},

// /** */
// /** @method */
// objectStoreNames: function() {
// return Q.defer()
// .resolve(_.keys(this._stores));
// },

/** */
/** @method */
objectStore: function(name, options) {
var url = this.url + name;
return new ElasticSearchStore(this, name, url, options);
},

// /** */
// /** @method */
// createObjectStore: function(name, options) {
// return Q.defer()
// .resolve(this.objectStore(name, options));
// },

// /** */
// /** @method */
// deleteObjectStore: function(name) {
// return Q.defer()
// .resolve(delete this._stores[name]);
Expand All @@ -77,19 +79,20 @@ var ElasticSearchBackend = BaseBackend.extend(



/** @class ElasticSearchStore */
/** @class ElasticSearchStore
@extends BaseStore */
var ElasticSearchStore = BaseBackend.BaseStore.extend(
/** @lends ElasticSearchStore# */
{
/** */
/** @method */
initialize: function(backend, name, url, options) {
options = _.extend({keyPath: '_id'}, options || {});
BaseBackend.BaseStore.prototype.initialize.call(this, backend, name, options);

this._url = url;
},

/** */
/** @method */
get: function(directives) {
var key = this._getObjectKey({}, directives);

Expand All @@ -99,12 +102,12 @@ var ElasticSearchStore = BaseBackend.BaseStore.extend(
});
},

/** */
/** @method */
add: function(object, directives) {
return ElasticSearchStore.prototype.put.call(this, object, directives);
},

/** */
/** @method */
put: function(object, directives) {
object = _.clone(object);
var self = this;
Expand Down Expand Up @@ -136,7 +139,7 @@ var ElasticSearchStore = BaseBackend.BaseStore.extend(
});
},

/** */
/** @method */
'delete': function(directives) {
var key = this._getObjectKey({}, directives);

Expand Down
36 changes: 23 additions & 13 deletions backend/fs.js
Expand Up @@ -10,27 +10,28 @@ function resolvedPromise(val) {
return d.promise;
}

/** @class FsBackend */
/** @class FsBackend
@extends BaseBackend */
var FsBackend = BaseBackend.extend(
/** @lends FsBackend# */
{
/** */
/** @method */
initialize: function(options) {
BaseBackend.prototype.initialize.call(this, options);
},

/** */
/** @method */
objectStoreNames: function() {
return Q.ninvoke(fs, 'readdir', this.options.path);
},

/** */
/** @method */
objectStore: function(name, options) {
name = path.basename(name);
return new FsStore(this, name, options);
},

/** */
/** @method */
createObjectStore: function(name, options) {
var d = Q.defer();
name = path.basename(name);
Expand All @@ -40,29 +41,36 @@ var FsBackend = BaseBackend.extend(
return d.promise;
},

/** */
/** @method */
deleteObjectStore: function(name) {
name = path.basename(name);
this.objectStore(name).clear().then(function() {
return Q.ninvoke(fs, 'rmdir', path.join(this.options.path, name));
});
},
/** Encode object into string, by default uses JSON.stringify
Override to use different serialization
@method */
encode: JSON.stringify,
/** Decode string into object, by default uses JSON.parse
Override to use different serialization
@method */
decode: JSON.parse
});



/** @class FsStore */
/** @class FsStore
@extends BaseStore */
var FsStore = BaseBackend.BaseStore.extend(
/** @lends FsStore# */
{
/** */
/** @method */
initialize: function(backend, name, options) {
BaseBackend.BaseStore.prototype.initialize.call(this, backend, name, options);
},

/** */
/** @method */
get: function(directives) {
var key = this._getObjectKey({}, directives);
return Q.ninvoke(fs, 'readFile', this.filename(key), 'utf-8')
Expand All @@ -71,7 +79,7 @@ var FsStore = BaseBackend.BaseStore.extend(
}.bind(this));
},

/** */
/** @method */
add: function(object, directives) {
var key = this._getObjectKey(object, directives);

Expand All @@ -80,7 +88,7 @@ var FsStore = BaseBackend.BaseStore.extend(
});
},

/** */
/** @method */
put: function(object, directives) {
var key = this._getObjectKey(object, directives);

Expand All @@ -89,7 +97,7 @@ var FsStore = BaseBackend.BaseStore.extend(
});
},

/** */
/** @method */
'delete': function(directives) {
var key = this._getObjectKey({}, directives),
d = Q.defer();
Expand Down Expand Up @@ -133,11 +141,13 @@ var FsStore = BaseBackend.BaseStore.extend(
});
},

/** Get absolute filename for given key */
filename: function(file) {

return path.join(this.backend.options.path, this.name, ''+path.basename(file));
}
});

/** @module fs */

FsBackend.FsStore = FsStore;
module.exports = FsBackend;

0 comments on commit d5a964a

Please sign in to comment.