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:
parent
a9dd5b80cd
commit
cb492c0747
55
lib/robot.js
55
lib/robot.js
|
@ -157,19 +157,7 @@ Robot.prototype.initRobot = function(opts) {
|
||||||
Robot.prototype.initConnections = function(opts) {
|
Robot.prototype.initConnections = function(opts) {
|
||||||
this.log("info", "Initializing connections.");
|
this.log("info", "Initializing connections.");
|
||||||
|
|
||||||
if (opts.connection == null && opts.connections == null) {
|
if (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");
|
|
||||||
return this.connections;
|
return this.connections;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -189,7 +177,6 @@ Robot.prototype.initConnections = function(opts) {
|
||||||
|
|
||||||
this.connection(name, conn);
|
this.connection(name, conn);
|
||||||
}, this);
|
}, this);
|
||||||
}
|
|
||||||
|
|
||||||
return this.connections;
|
return this.connections;
|
||||||
};
|
};
|
||||||
|
@ -237,7 +224,7 @@ Robot.prototype.device = function(name, device) {
|
||||||
Robot.prototype.initDevices = function(opts) {
|
Robot.prototype.initDevices = function(opts) {
|
||||||
this.log("info", "Initializing devices.");
|
this.log("info", "Initializing devices.");
|
||||||
|
|
||||||
if (opts.device == null && opts.devices == null) {
|
if (opts.devices == null) {
|
||||||
return this.devices;
|
return this.devices;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -246,23 +233,10 @@ Robot.prototype.initDevices = function(opts) {
|
||||||
throw new Error("No connections specified");
|
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) {
|
_.each(opts.devices, function(device, key) {
|
||||||
var name = _.isString(key) ? key : device.name;
|
var name = _.isString(key) ? key : device.name;
|
||||||
this.device(name, device);
|
this.device(name, device);
|
||||||
}, this);
|
}, this);
|
||||||
}
|
|
||||||
|
|
||||||
return this.devices;
|
return this.devices;
|
||||||
};
|
};
|
||||||
|
@ -424,28 +398,3 @@ Robot.prototype.log = function(level) {
|
||||||
args.unshift("[" + this.name + "] -");
|
args.unshift("[" + this.name + "] -");
|
||||||
Logger[level].apply(null, args);
|
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);
|
|
||||||
};
|
|
||||||
|
|
|
@ -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() {
|
context("when passed an object containing connection details", function() {
|
||||||
it("creates new connections with each of the ones provided", function() {
|
it("creates new connections with each of the ones provided", function() {
|
||||||
var connections = {
|
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() {
|
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() {
|
context("when passed an object containing device details", function() {
|
||||||
it("creates new devices with each of the ones provided", function() {
|
it("creates new devices with each of the ones provided", function() {
|
||||||
var devices = {
|
var devices = {
|
||||||
|
@ -427,27 +389,6 @@ describe("Robot", function() {
|
||||||
expect(bot.devices.ping).to.be.instanceOf(Driver);
|
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() {
|
describe("#start", function() {
|
||||||
|
|
Loading…
Reference in New Issue