Expose commands as array, instead of function

For appropriate classes, #commands is now an array, instead of a function that
returns the same array.
This commit is contained in:
Andrew Stewart 2014-06-10 12:29:44 -07:00
parent 9406fddaad
commit 1832e20e17
12 changed files with 19 additions and 69 deletions

View File

@ -32,18 +32,11 @@ module.exports = Adaptor = function Adaptor(opts) {
this.self = this;
this.name = opts.name;
this.connection = opts.connection;
this.commandList = [];
this.commands = [];
};
Utils.subclass(Adaptor, Basestar);
// Public: Exposes all commands the adaptor will respond to/proxy
//
// Returns an array of string method names
Adaptor.prototype.commands = function() {
return this.commandList;
};
// Public: Connects to the adaptor, and triggers the provided callback when
// done.
//

View File

@ -46,7 +46,7 @@ module.exports = Connection = function Connection(opts) {
this.port = opts.port;
this.adaptor = this.initAdaptor(opts);
Utils.proxyFunctionsToObject(this.adaptor.commands(), this.adaptor, this.self);
Utils.proxyFunctionsToObject(this.adaptor.commands, this.adaptor, this.self);
}
Utils.subclass(Connection, EventEmitter);

View File

@ -43,7 +43,7 @@ module.exports = Device = function Device(opts) {
this.connection = this.determineConnection(opts.connection) || this.defaultConnection();
this.driver = this.initDriver(opts);
Utils.proxyFunctionsToObject(this.driver.commands(), this.driver, this.self);
Utils.proxyFunctionsToObject(this.driver.commands, this.driver, this.self);
};
Utils.subclass(Device, EventEmitter);
@ -83,7 +83,7 @@ Device.prototype.toJSON = function() {
driver: this.driver.constructor.name || this.driver.name,
pin: this.pin,
connection: this.connection.toJSON(),
commands: this.driver.commands()
commands: this.driver.commands
};
};

View File

@ -33,18 +33,11 @@ module.exports = Driver = function Driver(opts) {
this.name = opts.name;
this.device = opts.device;
this.connection = this.device.connection;
this.commandList = [];
this.commands = [];
};
Utils.subclass(Driver, Basestar);
// Public: Exposes all commands the driver will respond to/proxy
//
// Returns an array of string method names
Driver.prototype.commands = function() {
return this.commandList;
};
// Public: Starts up the driver, and triggers the provided callback when done.
//
// callback - function to run when the driver is started

View File

@ -298,7 +298,7 @@ Robot.prototype.initAdaptor = function(adaptorName, connection, opts) {
connection: connection,
extraParams: opts
});
return Utils.proxyTestStubs(adaptor.commands(), testAdaptor);
return Utils.proxyTestStubs(adaptor.commands, testAdaptor);
} else {
return adaptor;
}
@ -363,7 +363,7 @@ Robot.prototype.initDriver = function(driverName, device, opts) {
extraParams: opts
});
return Utils.proxyTestStubs(driver.commands(), testDriver);
return Utils.proxyTestStubs(driver.commands, testDriver);
} else {
return driver;
}

View File

@ -15,12 +15,9 @@ var Loopback;
module.exports = Loopback = function Loopback() {
Loopback.__super__.constructor.apply(this, arguments);
this.commands = ['ping'];
};
Utils.subclass(Loopback, Adaptor);
Loopback.prototype.commands = function() {
return ['ping'];
};
Loopback.adaptor = function(opts) { return new Loopback(opts); };

View File

@ -15,14 +15,11 @@ var Ping;
module.exports = Ping = function Ping() {
Ping.__super__.constructor.apply(this, arguments);
this.commands = ['ping'];
};
Utils.subclass(Ping, Driver);
Ping.prototype.commands = function() {
return ['ping'];
};
Ping.prototype.ping = function() {
return "pong";
};

View File

@ -155,7 +155,7 @@ var Utils = module.exports = {
return true;
};
base.commandList.push(method);
base.commands.push(method);
});
return base;

View File

@ -23,23 +23,8 @@ describe("Adaptor", function() {
expect(adaptor.connection).to.be.eql(connection);
});
it("sets @commandList to an empty array by default", function() {
expect(adaptor.commandList).to.be.eql([]);
});
});
describe("#commands", function() {
var commands = ['list', 'of', 'commands']
before(function() {
adaptor.commandList = commands;
});
after(function() {
adaptor.commandList = [];
});
it("returns the adaptor's @commandList", function() {
expect(adaptor.commands()).to.be.eql(commands);
it("sets @commands to an empty array by default", function() {
expect(adaptor.commands).to.be.eql([]);
});
});

View File

@ -134,7 +134,7 @@ describe("Device", function() {
});
it("contains the device's driver commands", function() {
expect(json.commands).to.be.eql(driver.commands());
expect(json.commands).to.be.eql(driver.commands);
});
});

View File

@ -34,23 +34,8 @@ describe("Driver", function() {
expect(driver.connection).to.be.eql(device.connection);
});
it("sets @commandList to an empty array by default", function() {
expect(driver.commandList).to.be.eql([]);
});
});
describe("#commands", function() {
var commands = ['list', 'of', 'commands']
before(function() {
driver.commandList = commands;
});
after(function() {
driver.commandList = [];
});
it("returns the driver's @commandList", function() {
expect(driver.commands()).to.be.eql(commands);
it("sets @commands to an empty array by default", function() {
expect(driver.commands).to.be.eql([]);
});
});

View File

@ -172,17 +172,17 @@ describe("Utils", function() {
});
describe("#proxyTestStubs", function() {
it("proxies methods to an object's commandList", function() {
it("proxies methods to an object's commands", function() {
var methods = ["hello", "goodbye"],
base = { commandList: [] };
base = { commands: [] };
utils.proxyTestStubs(methods, base);
expect(base.commandList).to.be.eql(methods);
expect(base.commands).to.be.eql(methods);
});
it("returns the object methods have been proxied to", function() {
var methods = ["hello", "goodbye"],
base = { commandList: [] };
base = { commands: [] };
expect(utils.proxyTestStubs(methods, base)).to.be.eql(base);
});