Remove deprecated Connection / Device syntaxes

Removes deprecation warnings + support for single-object + array
syntaxes.

The array syntax will likely continue to work due to the `_.each`
abstraction, but since we don't use it anywhere, the requisite specs
have been removed.
This commit is contained in:
Andrew Stewart 2015-03-04 09:27:33 -08:00
parent a9dd5b80cd
commit cb492c0747
2 changed files with 19 additions and 129 deletions

View File

@ -157,19 +157,7 @@ Robot.prototype.initRobot = function(opts) {
Robot.prototype.initConnections = function(opts) {
this.log("info", "Initializing connections.");
if (opts.connection == null && opts.connections == null) {
return this.connections;
}
if (opts.connection) {
this.deprecationWarning("connection");
this.connection(opts.connection.name, opts.connection);
return this.connections;
}
if (_.isObjectLoose(opts.connections)) {
if (_.isArray(opts.connections)) {
this.performArraySetup(opts.connections, "connection", "connections");
if (opts.connections == null) {
return this.connections;
}
@ -189,7 +177,6 @@ Robot.prototype.initConnections = function(opts) {
this.connection(name, conn);
}, this);
}
return this.connections;
};
@ -237,7 +224,7 @@ Robot.prototype.device = function(name, device) {
Robot.prototype.initDevices = function(opts) {
this.log("info", "Initializing devices.");
if (opts.device == null && opts.devices == null) {
if (opts.devices == null) {
return this.devices;
}
@ -246,23 +233,10 @@ Robot.prototype.initDevices = function(opts) {
throw new Error("No connections specified");
}
if (opts.device) {
this.deprecationWarning("device");
this.device(opts.device.name, opts.device);
return this.devices;
}
if (_.isObjectLoose(opts.devices)) {
if (_.isArray(opts.devices)) {
this.performArraySetup(opts.devices, "device", "devices");
return this.devices;
}
_.each(opts.devices, function(device, key) {
var name = _.isString(key) ? key : device.name;
this.device(name, device);
}, this);
}
return this.devices;
};
@ -424,28 +398,3 @@ Robot.prototype.log = function(level) {
args.unshift("[" + this.name + "] -");
Logger[level].apply(null, args);
};
Robot.prototype.performArraySetup = function(things, typeOfThing, arrayName) {
var str = "Specifying ";
str += arrayName;
str += " as an array is deprecated. ";
str += "It will be removed in 1.0.0.";
this.log("warn", str);
things.forEach(function(t, key) {
var name = _.isString(key) === "string" ? key : t.name;
this[typeOfThing](name, t);
}, this);
};
Robot.prototype.deprecationWarning = function(kind) {
var msg = "Specifying a single ";
msg += kind;
msg += " with the '";
msg += kind;
msg += "' key ";
msg += "is deprecated. It will be removed in 1.0.0.";
this.log("warn", msg);
};

View File

@ -294,14 +294,6 @@ describe("Robot", function() {
});
});
context("when passed a connection object", function() {
it("instantiates a new connection with the provided object", function() {
var connection = { name: "loopback", adaptor: "loopback" };
bot.initConnections({ connection: connection });
expect(bot.connections["loopback"]).to.be.instanceOf(Adaptor);
});
});
context("when passed an object containing connection details", function() {
it("creates new connections with each of the ones provided", function() {
var connections = {
@ -341,28 +333,6 @@ describe("Robot", function() {
});
});
});
context("when passed an array of connection objects", function() {
it("creates new connections with each of the ones provided", function() {
var connections = [{ name: "loopback", adaptor: "loopback" }];
bot.initConnections({ connections: connections });
expect(bot.connections["loopback"]).to.be.instanceOf(Adaptor);
});
it("avoids name collisions", function() {
var opts = {
connections: [
{ name: "loopback", adaptor: "loopback" },
{ name: "loopback", adaptor: "loopback" }
]
};
bot.initConnections(opts);
var keys = Object.keys(bot.connections);
expect(keys).to.be.eql(["loopback", "loopback-1"]);
});
});
});
describe("#device", function() {
@ -409,14 +379,6 @@ describe("Robot", function() {
});
});
context("when passed a device object", function() {
it("instantiates a new driver with the provided object", function() {
var device = { name: "ping", driver: "ping" };
bot.initDevices({ device: device });
expect(bot.devices["ping"]).to.be.instanceOf(Driver);
});
});
context("when passed an object containing device details", function() {
it("creates new devices with each of the ones provided", function() {
var devices = {
@ -427,27 +389,6 @@ describe("Robot", function() {
expect(bot.devices.ping).to.be.instanceOf(Driver);
});
});
context("when passed an array of device objects", function() {
it("instantiates new drivers with provided objects", function() {
var devices = [{ name: "ping", driver: "ping" }];
bot.initDevices({ devices: devices});
expect(bot.devices["ping"]).to.be.instanceOf(Driver);
});
it("avoids name collisions collisions", function() {
bot.initDevices({
devices: [
{ name: "ping", driver: "ping" },
{ name: "ping", driver: "ping" }
]
});
var keys = Object.keys(bot.devices);
expect(keys).to.be.eql(["ping", "ping-1"]);
});
});
});
describe("#start", function() {