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

View File

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

View File

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

View File

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