Skip to content
This repository has been archived by the owner on Jul 12, 2023. It is now read-only.

Commit

Permalink
Control what modules are registered
Browse files Browse the repository at this point in the history
Change-Id: I4edd3dbb17cc2825618d532c571020c21dce7040
  • Loading branch information
piranna committed Apr 14, 2015
1 parent be51f36 commit bcf58d7
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
30 changes: 23 additions & 7 deletions lib/register.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ var checkType = require('checktype');
var abstracts = {};
var classes = {};
var complexTypes = {};
var modules = [];

function registerAbstracts(classes) {
for (var name in classes) {
Expand Down Expand Up @@ -42,6 +43,11 @@ function registerComplexTypes(types) {
}
}

function registerModule(name) {
modules.push(name)
modules.sort()
}

function register(name, constructor) {
// Adjust parameters
if (typeof name != 'string') {
Expand All @@ -55,8 +61,7 @@ function register(name, constructor) {
// Registering a function
if (constructor instanceof Function) {
// Registration name
if (!name)
name = constructor.name
if (!name) name = constructor.name

if (name == undefined)
throw new Error("Can't register an anonymous module");
Expand All @@ -65,24 +70,35 @@ function register(name, constructor) {
}

// Registering a plugin
else
for (key in constructor)
else {
if (!name) name = constructor.name

if (name) registerModule(name)

for (var key in constructor) {
var value = constructor[key]

if (typeof value === 'string') continue

switch (key) {
case 'abstracts':
registerAbstracts(constructor[key])
registerAbstracts(value)
break

case 'complexTypes':
registerComplexTypes(constructor[key])
registerComplexTypes(value)
break

default:
registerClass(key, constructor[key])
registerClass(key, value)
}
}
}
};

module.exports = register;

register.abstracts = abstracts;
register.classes = classes;
register.complexTypes = complexTypes;
register.modules = modules;
4 changes: 4 additions & 0 deletions templates/model_index.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ index.js
* @license LGPL
*/

Object.defineProperty(exports, 'name', {value: '${module.name}'});
Object.defineProperty(exports, 'version', {value: '${module.version}'});


<#list module.remoteClasses?sort_by("name") as remoteClass>
<#if !remoteClass.abstract>
var ${remoteClass.name} = require('./${remoteClass.name}');
Expand Down

0 comments on commit bcf58d7

Please sign in to comment.