Remove node-namespace from Adaptor

This commit is contained in:
Andrew Stewart 2014-05-06 18:18:20 -07:00
parent 2958f148f3
commit 637bce0e6d
4 changed files with 49 additions and 51 deletions

View File

@ -10,59 +10,53 @@
var Basestar = require('./basestar');
var namespace = require('node-namespace');
// The Adaptor class is a base class for Adaptor classes in external Cylon
// modules to use. It offers basic functions for connecting/disconnecting that
// descendant classes can use.
namespace("Cylon", function() {
this.Adaptor = (function(klass) {
subclass(Adaptor, klass);
var Adaptor;
// Public: Creates a new Adaptor
//
// opts - hash of acceptable params
// name - name of the Adaptor, used when printing to console
// connection - Connection the adaptor will use to proxy commands/events
//
// Returns a new Adaptor
function Adaptor(opts) {
if (opts == null) {
opts = {};
}
this.self = this;
this.name = opts.name;
this.connection = opts.connection;
this.commandList = [];
}
// Public: Creates a new Adaptor
//
// opts - hash of acceptable params
// name - name of the Adaptor, used when printing to console
// connection - Connection the adaptor will use to proxy commands/events
//
// Returns a new Adaptor
module.exports = Adaptor = function Adaptor(opts) {
if (opts == null) {
opts = {};
}
// Public: Exposes all commands the adaptor will respond to/proxy
//
// Returns an array of string method names
Adaptor.prototype.commands = function() {
return this.commandList;
};
this.self = this;
this.name = opts.name;
this.connection = opts.connection;
this.commandList = [];
};
// Public: Connects to the adaptor, and emits 'connect' from the @connection
// when done.
//
// callback - function to run when the adaptor is connected
//
// Returns nothing
Adaptor.prototype.connect = function(callback) {
Logger.info("Connecting to adaptor '" + this.name + "'...");
callback(null);
return this.connection.emit('connect');
};
subclass(Adaptor, Basestar);
// Public: Disconnects from the adaptor
//
// Returns nothing
Adaptor.prototype.disconnect = function() {
return Logger.info("Disconnecting from adaptor '" + this.name + "'...");
};
// Public: Exposes all commands the adaptor will respond to/proxy
//
// Returns an array of string method names
Adaptor.prototype.commands = function() {
return this.commandList;
};
return Adaptor;
// Public: Connects to the adaptor, and emits 'connect' from the @connection
// when done.
//
// callback - function to run when the adaptor is connected
//
// Returns nothing
Adaptor.prototype.connect = function(callback) {
Logger.info("Connecting to adaptor '" + this.name + "'...");
callback(null);
return this.connection.emit('connect');
};
})(Basestar);
});
// Public: Disconnects from the adaptor
//
// Returns nothing
Adaptor.prototype.disconnect = function() {
return Logger.info("Disconnecting from adaptor '" + this.name + "'...");
};

View File

@ -10,6 +10,8 @@
var namespace = require('node-namespace');
var Adaptor = require('../adaptor');
module.exports = {
adaptor: function(opts) {
return new Cylon.Adaptors.Loopback(opts);
@ -31,5 +33,5 @@ namespace("Cylon.Adaptors", function() {
return Loopback;
})(Cylon.Adaptor);
})(Adaptor);
});

View File

@ -10,6 +10,8 @@
var namespace = require('node-namespace');
var Adaptor = require('../adaptor')
module.exports = {
adaptor: function(opts) {
return new Cylon.Adaptors.TestAdaptor(opts);
@ -29,5 +31,5 @@ namespace("Cylon.Adaptors", function() {
return TestAdaptor;
})(Cylon.Adaptor);
})(Adaptor);
});

View File

@ -2,11 +2,11 @@
var EventEmitter = require('events').EventEmitter;
source("adaptor");
var Adaptor = source("adaptor");
describe("Adaptor", function() {
var connection = new EventEmitter;
var adaptor = new Cylon.Adaptor({ name: 'adaptor', connection: connection });
var adaptor = new Adaptor({ name: 'adaptor', connection: connection });
describe("#constructor", function() {
it("sets @self as a reference to the adaptor", function() {