From 541d70b66da0ad07724d112aefad8b971df72762 Mon Sep 17 00:00:00 2001 From: Andrew Stewart Date: Wed, 23 Oct 2013 10:10:25 -0700 Subject: [PATCH] Correctly set up loopback adaptor --- src/loopback.coffee | 9 +++++---- src/robot.coffee | 12 ++++++------ 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/loopback.coffee b/src/loopback.coffee index e6bf0b2..5a77bd3 100644 --- a/src/loopback.coffee +++ b/src/loopback.coffee @@ -8,12 +8,13 @@ 'use strict'; -exports.adaptor = (opts = {}) -> - new Loopback(opts) +module.exports = + adaptor: (opts = {}) -> + new Loopback(opts) -module.exports = class Loopback +class Loopback self = this - + constructor: (opts) -> @name = opts.name diff --git a/src/robot.coffee b/src/robot.coffee index abbfa25..98d2266 100644 --- a/src/robot.coffee +++ b/src/robot.coffee @@ -14,6 +14,7 @@ Device = require("./device") module.exports = class Robot self = this + @adaptors = {} constructor: (opts = {}) -> @name = opts.name or @constructor.randomName() @@ -67,14 +68,13 @@ module.exports = class Robot device.start() self[device.name] = device - requireAdaptor: (adaptorName, connection) -> - require("cylon-#{@adaptors[adaptorName]}").register(self) unless @adaptors[adaptorName]? - require(@adaptors[adaptorName]).adaptor(adaptorName)(connection: connection) + @requireAdaptor = (adaptorName, connection) -> + require("cylon-#{adaptorName}").register(self) unless self.adaptors[adaptorName]? + require(self.adaptors[adaptorName]).adaptor(name: adaptorName).connect(connection: connection) registerAdaptor: (moduleName, adaptorName) -> - @adaptors ?= {} - return if @adaptors[adaptorName]? - @adaptors[adaptorName] = moduleName + return if self.adaptors[adaptorName]? + self.adaptors[adaptorName] = moduleName requireDriver: (driverName, device) -> require("cylon-#{@drivers[driverName]}").register(self) unless @drivers[driverName]?