hybridgroup/cylon — pull request #237 by stewart (2014-10-30 20:39:08+00:00)
Title: Add Repository class, restructure external module loading

This PR removes the responsibility of keeping track of modules from the Robot class, splitting it off into the Repository module.

It also introduces a changes to how the submodule registration is done.

Using `cylon-firmata as an example, the current `module.exports` section looks like this:

```javascript
var Cylon = require("cylon");

var Adaptor = require("./firmata");

var GPIO = require("cylon-gpio"),
I2C = require("cylon-i2c");

module.exports = {
adaptor: function(args) {
return new Adaptor(args);
},

register: function(robot) {
Cylon.Logger.debug("Registering Firmata adaptor for " + robot.name);
robot.registerAdaptor('cylon-firmata', 'firmata');

GPIO.register(robot);
I2C.register(robot);
}
};
```

This PR changes format such that the following would be the replacement:

```javascript
var Adaptor = require('./firmata');

module.exports = {
adaptors: ['firmata'],
dependencies: ['cylon-gpio', 'cylon-i2c'],

adaptor: function(args) {
return new Adaptor(args);
}
};
```

or, e.g., `cylon-leapmotion`:

```javascript
var Adaptor = require('./adaptor'),
Driver = require('./driver');

module.exports = {
adaptors: ['leapmotion'],
drivers: ['leapmotion'],

adaptor: function(opts) {
return new Adaptor(opts);
},

driver: function(opts) {
return new Driver(opts);
}
};
```

The job of initializing Adaptors/Drivers is now moved from the Robot to the Connection/Device classes, respectively.
This is in anticipation of the next set of changes that aims to fully remove those (Connection/Device) classes, replacing them instead with functions that return Adaptor/Driver instances.

The new registration system is also cleaner and makes easier to see at a glance what adaptors/drivers a module exports, along with what dependencies (GPIO/I2C) it has.

The downside is that this batch of changes will require quick modifications to the index file of all Cylon submodules to switch them over to this format.