forked from thenativeweb/node-cqrs-eventdenormalizer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
34 lines (29 loc) · 916 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
var Denormalizer = require('./lib/denormalizer'),
_ = require('lodash'),
fs = require('fs'),
path = require('path');
function denormalizer (options) {
return new Denormalizer(options);
}
/**
* Calls the constructor.
* @param {Object} klass Constructor function.
* @param {Array} args Arguments for the constructor function.
* @return {Object} The new object.
*/
function construct(klass, args) {
function T() {
klass.apply(this, arguments[0]);
}
T.prototype = klass.prototype;
return new T(args);
}
var files = fs.readdirSync(path.join(__dirname, 'lib/definitions'));
files.forEach(function (file) {
var name = path.basename(file, '.js');
var nameCap = name.charAt(0).toUpperCase() + name.slice(1);
denormalizer['define' + nameCap] = function () {
return construct(require('./lib/definitions/' + name), _.toArray(arguments));
};
});
module.exports = denormalizer;