Namespace Robot class

This commit is contained in:
Andrew Stewart 2013-11-04 11:57:27 -08:00
parent 483dcf26b9
commit 9d48cba3cf
4 changed files with 359 additions and 349 deletions

10
dist/robot.js vendored
View File

@ -9,7 +9,7 @@
(function() {
'use strict';
var Async, Connection, Device, Robot,
var Async, Connection, Device, namespace,
__bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
__indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
@ -17,13 +17,16 @@
require('./basestar');
namespace = require('node-namespace');
Connection = require("./connection");
Device = require("./device");
Async = require("async");
module.exports = Robot = (function() {
namespace('Cylon', function() {
return this.Robot = (function() {
var klass;
klass = Robot;
@ -218,5 +221,8 @@
return Robot;
})();
});
module.exports = Cylon.Robot;
}).call(this);

View File

@ -8,15 +8,19 @@
'use strict';
require('./cylon')
require('./basestar')
Connection = require("./connection")
Device = require("./device")
Async = require("async")
require './cylon'
require './basestar'
namespace = require 'node-namespace'
Connection = require "./connection"
Device = require "./device"
Async = require "async"
# A Robot is the primary interface for interacting with a collection of physical
# computing capabilities.
module.exports = class Robot
namespace 'Cylon', ->
class @Robot
klass = this
# Public: Creates a new Robot
@ -196,3 +200,5 @@ module.exports = class Robot
registerDriver: (moduleName, driverName) =>
return if @drivers[driverName]?
@drivers[driverName] = moduleName
module.exports = Cylon.Robot

View File

@ -1,8 +1,6 @@
(function() {
'use strict';
var Robot;
Robot = source("robot");
source("robot");
source("logger");
@ -16,7 +14,7 @@
whateverFunc = function() {
return Logger.info("whatever!");
};
robot = new Robot({
robot = new Cylon.Robot({
name: "irobot",
work: testWork,
whatever: whateverFunc
@ -26,8 +24,8 @@
});
it("has a random name, if not given", function() {
var r;
sinon.stub(Robot, 'randomName').returns('Electra');
r = new Robot;
sinon.stub(Cylon.Robot, 'randomName').returns('Electra');
r = new Cylon.Robot;
return r.name.should.be.equal('Electra');
});
it("has work", function() {

View File

@ -1,25 +1,25 @@
'use strict';
Robot = source("robot")
source("robot")
source("logger")
Logger.setup(false) # quiet logger for tests
describe "Robot", ->
testWork = ->
Logger.info "hi"
testWork = -> Logger.info "hi"
whateverFunc = -> Logger.info "whatever!"
whateverFunc = ->
Logger.info "whatever!"
robot = new Robot(name: "irobot", work: testWork, whatever: whateverFunc)
robot = new Cylon.Robot
name: "irobot"
work: testWork
whatever: whateverFunc
it "has a name, if given", ->
robot.name.should.be.equal 'irobot'
it "has a random name, if not given", ->
sinon.stub(Robot, 'randomName').returns('Electra')
r = new Robot
sinon.stub(Cylon.Robot, 'randomName').returns('Electra')
r = new Cylon.Robot
r.name.should.be.equal 'Electra'
it "has work", ->