From 51d4a7426473407eecb3010c54bbdd0ae30008c2 Mon Sep 17 00:00:00 2001 From: Ritchie Martori Date: Tue, 11 Jun 2013 09:04:37 -0700 Subject: [PATCH] Revert "Asteroid 0.7 updates" This reverts commit c87abafec8ba734f90c9bfdda415859e63f66939. --- lib/datasource.js | 167 ++-------------------------------------------- 1 file changed, 4 insertions(+), 163 deletions(-) diff --git a/lib/datasource.js b/lib/datasource.js index 062a4a61..d666ab9c 100644 --- a/lib/datasource.js +++ b/lib/datasource.js @@ -60,40 +60,6 @@ function DataSource(name, settings) { // default DataAccessObject this.DataAccessObject = this.constructor.DataAccessObject; this.DataAccessObject.call(this, arguments); - - // operation metadata - this._operations = {}; - - // define DataAccessObject methods - Object.keys(this.DataAccessObject).forEach(function (name) { - var fn = this.DataAccessObject[name]; - - if(typeof fn === 'function') { - this.defineOperation(name, { - accepts: fn.accepts, - returns: fn.returns, - http: fn.http, - remoteEnabled: fn.share, - fn: fn - }); - } - }.bind(this)); - - // define DataAccessObject.prototype methods - Object.keys(this.DataAccessObject.prototype).forEach(function (name) { - var fn = this.DataAccessObject.prototype[name]; - - if(typeof fn === 'function') { - this.defineOperation(name, { - prototype: true, - accepts: fn.accepts, - returns: fn.returns, - http: fn.http, - remoteEnabled: fn.share, - fn: fn - }); - } - }.bind(this)); }; util.inherits(DataSource, ModelBuilder); @@ -110,14 +76,6 @@ for (var m in ModelBuilder) { DataSource.prototype.setup = function(name, settings) { var schema = this; - var adapter; - - // support single settings object - if(typeof name === 'object') { - settings = name; - name = undefined; - adapter = settings.connector || settings.adapter; - } // just save everything we get this.name = name; @@ -127,10 +85,11 @@ DataSource.prototype.setup = function(name, settings) { this.connected = false; this.connecting = false; - if (name && !adapter) { + if (name) { // and initialize schema using adapter // this is only one initialization entry point of adapter // this module should define `adapter` member of `this` (schema) + var adapter; if (typeof name === 'object') { adapter = name; this.name = adapter.name; @@ -202,15 +161,6 @@ DataSource.prototype.setup = function(name, settings) { }; } -/** - * Get the connector. - */ - -DataSource.prototype.connector = function () { - // alias for adapter compatibility - return this.adapter; -}; - /** * Define class * @@ -270,38 +220,15 @@ DataSource.prototype.define = function defineClass(className, properties, settin }; -// alias createModel -DataSource.prototype.createModel = DataSource.prototype.define; - /** * Mixin DataAccessObject methods. */ DataSource.prototype.mixin = function (ModelCtor) { - var ops = this.operations(); - // mixin enabled operations as alias functions - Object.keys(ops).forEach(function (name) { - console.log(name); - - var op = ops[name]; - var fn = op.fn; - var scope; + // inherit DataAccessObject methods + jutil.mixin(ModelCtor, this.DataAccessObject); - if(op.enabled) { - scope = op.prototype ? ModelCtor.prototype : ModelCtor; - var sfn = scope[name] = function () { - fn.apply(this, arguments); - } - Object.keys(op).forEach(function (key) { - if(key !== 'fn' && key !== 'prototype') { - if(typeof op[key] !== 'undefined') { - sfn[key] = op[key]; - } - } - }); - } - }.bind(this)); } /** @@ -1144,92 +1071,6 @@ DataSource.prototype.transaction = function() { return transaction; }; -/** - * Enable a data source operation. - */ - -DataSource.prototype.enable = function (operation) { - var op = this.getOperation(operation); - if(op) { - op.enabled = true; - } else { - throw new Error(operation + ' is provided by the attached connector'); - } -} - -/** - * Enable a data source operation remotely. - */ - -DataSource.prototype.enableRemote = function (operation) { - var op = this.getOperation(operation); - if(op) { - op.remoteEnabled = true; - } else { - throw new Error(operation + ' is provided by the attached connector'); - } -} - -/** - * Disable a data source operation. - */ - -DataSource.prototype.disable = function (operation) { - var op = this.getOperation(operation); - if(op) { - op.enabled = false; - } else { - throw new Error(operation + ' is provided by the attached connector'); - } -} - -/** - * Disable a data source operation remotely. - */ - -DataSource.prototype.disableRemote = function (operation) { - var op = this.getOperation(operation); - if(op) { - op.remoteEnabled = false; - } else { - throw new Error(operation + ' is provided by the attached connector'); - } -} - -/** - * Get an operation's metadata. - */ - -DataSource.prototype.getOperation = function (operation) { - var ops = this.operations(); - - for(var i = 0; i < ops.length; i++) { - var op = ops[i]; - - if(op.name === operation) { - return op; - } - } -} - -/** - * Get all operations. - */ - -DataSource.prototype.operations = function () { - return this._operations; -} - -/** - * Define an operation. - */ - -DataSource.prototype.defineOperation = function (name, options, fn) { - options.fn = fn; - options.enabled = true; - this._operations[name] = options; -} - /** * Define hidden property */