Namespace Device class
This commit is contained in:
parent
ae666f67dd
commit
eda6f9db76
|
@ -9,16 +9,19 @@
|
|||
|
||||
(function() {
|
||||
'use strict';
|
||||
var Device, EventEmitter,
|
||||
var EventEmitter, namespace,
|
||||
__bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
|
||||
__hasProp = {}.hasOwnProperty,
|
||||
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
|
||||
|
||||
require('./cylon');
|
||||
|
||||
namespace = require('node-namespace');
|
||||
|
||||
EventEmitter = require('events').EventEmitter;
|
||||
|
||||
module.exports = Device = (function(_super) {
|
||||
namespace('Cylon', function() {
|
||||
return this.Device = (function(_super) {
|
||||
__extends(Device, _super);
|
||||
|
||||
function Device(opts) {
|
||||
|
@ -83,5 +86,8 @@
|
|||
return Device;
|
||||
|
||||
})(EventEmitter);
|
||||
});
|
||||
|
||||
module.exports = Cylon.Device;
|
||||
|
||||
}).call(this);
|
||||
|
|
|
@ -8,13 +8,15 @@
|
|||
|
||||
'use strict';
|
||||
|
||||
require('./cylon')
|
||||
require './cylon'
|
||||
namespace = require 'node-namespace'
|
||||
EventEmitter = require('events').EventEmitter
|
||||
|
||||
# The Artoo::Device class represents the interface to
|
||||
# a specific individual hardware devices. Examples would be a digital
|
||||
# thermometer connected to an Arduino, or a Sphero's accelerometer.
|
||||
module.exports = class Device extends EventEmitter
|
||||
namespace 'Cylon', ->
|
||||
class @Device extends EventEmitter
|
||||
|
||||
# Public: Creates a new Device
|
||||
#
|
||||
|
@ -84,3 +86,5 @@ module.exports = class Device extends EventEmitter
|
|||
requireDriver: (opts = {}) ->
|
||||
Logger.debug "Loading driver '#{ opts.driver }'"
|
||||
@robot.requireDriver(opts.driver, @self, opts)
|
||||
|
||||
module.exports = Cylon.Device
|
||||
|
|
|
@ -1,23 +1,23 @@
|
|||
(function() {
|
||||
'use strict';
|
||||
var Device, Driver, Robot;
|
||||
var Driver;
|
||||
|
||||
Device = source("device");
|
||||
source("device");
|
||||
|
||||
source("robot");
|
||||
|
||||
Driver = source("driver");
|
||||
|
||||
Robot = source("robot");
|
||||
|
||||
describe("Device", function() {
|
||||
var device, driver, requireDriver, robot;
|
||||
robot = new Robot({
|
||||
robot = new Cylon.Robot({
|
||||
name: 'me'
|
||||
});
|
||||
driver = new Driver({
|
||||
name: 'driving'
|
||||
});
|
||||
requireDriver = sinon.stub(robot, 'requireDriver').returns(driver);
|
||||
device = new Device({
|
||||
device = new Cylon.Device({
|
||||
name: "devisive",
|
||||
driver: 'driving',
|
||||
robot: robot
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
'use strict';
|
||||
|
||||
Device = source("device")
|
||||
source("device")
|
||||
source("robot")
|
||||
Driver = source("driver")
|
||||
Robot = source("robot")
|
||||
|
||||
describe "Device", ->
|
||||
robot = new Robot(name: 'me')
|
||||
robot = new Cylon.Robot(name: 'me')
|
||||
driver = new Driver(name: 'driving')
|
||||
requireDriver = sinon.stub(robot, 'requireDriver').returns(driver)
|
||||
device = new Device(name: "devisive", driver: 'driving', robot: robot)
|
||||
device = new Cylon.Device(name: "devisive", driver: 'driving', robot: robot)
|
||||
|
||||
it "should belong to a robot", ->
|
||||
device.robot.name.should.be.equal 'me'
|
||||
|
|
Loading…
Reference in New Issue