From 6ac3cad7c146abed4e0271e7aa44614ca75e61c4 Mon Sep 17 00:00:00 2001 From: deadprogram Date: Sat, 17 Jan 2015 21:35:40 -0800 Subject: [PATCH] Extract even more of function to DRY up code --- lib/robot.js | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/lib/robot.js b/lib/robot.js index b62ba0c..b672e4a 100644 --- a/lib/robot.js +++ b/lib/robot.js @@ -167,12 +167,7 @@ Robot.prototype.initConnections = function(opts) { if (_.isObject(opts.connections)) { if (_.isArray(opts.connections)) { - str = "Specifying connections as an array is deprecated. "; - str += "It will be removed in 1.0.0."; - - Logger.warn(str); - - this.performArraySetup(opts.connections, "connection"); + this.performArraySetup(opts.connections, "connection", "connections"); return this.connections; } @@ -260,12 +255,7 @@ Robot.prototype.initDevices = function(opts) { if (_.isObject(opts.devices)) { if (_.isArray(opts.devices)) { - str = "Specifying devices as an array is deprecated. "; - str += "It will be removed in 1.0.0."; - - Logger.warn(str); - - this.performArraySetup(opts.devices, "device"); + this.performArraySetup(opts.devices, "device", "devices"); return this.devices; } @@ -414,7 +404,14 @@ Robot.prototype.toString = function() { return "[Robot name='" + this.name + "']"; }; -Robot.prototype.performArraySetup = function(things, typeOfThing) { +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."; + + Logger.warn(str); + _.forEach(things, function(t, key) { var name = _.isString(key) ? key : t.name; this[typeOfThing](name, t);