If key supplied in hash, use it to find module in Registry

This commit is contained in:
Andrew Stewart 2014-11-05 10:04:45 -08:00
parent e17dd743c9
commit 60e89c9671
3 changed files with 24 additions and 2 deletions

View File

@ -90,7 +90,13 @@ Connection.prototype.disconnect = function(callback) {
//
// Returns the set-up adaptor
Connection.prototype.initAdaptor = function(opts) {
var module = Registry.findByAdaptor(opts.adaptor);
var module;
if (opts.module) {
module = Registry.register(opts.module);
} else {
module = Registry.findByAdaptor(opts.adaptor);
}
opts.connection = this;

View File

@ -103,7 +103,13 @@ Device.prototype.toJSON = function() {
//
// Returns the set-up driver
Device.prototype.initDriver = function(opts) {
var module = Registry.findByDriver(opts.driver);
var module;
if (opts.module) {
module = Registry.register(opts.module);
} else {
module = Registry.findByDriver(opts.driver);
}
opts.device = this;

View File

@ -52,6 +52,8 @@ var Registry = module.exports = {
Registry.register(dep);
});
}
return this.data[module].module;
},
findByAdaptor: function(adaptor) {
@ -62,6 +64,14 @@ var Registry = module.exports = {
return this.search("drivers", driver);
},
findByModule: function(module) {
if (!this.data[module]) {
return null;
}
return this.data[module].module;
},
search: function(entry, value) {
for (var name in this.data) {
var repo = this.data[name];