1 |
|
2 |
|
3 |
|
4 | 'use strict';
|
5 |
|
6 | const path = require('path');
|
7 | const ClassHelper = require('../helper/ClassHelper');
|
8 |
|
9 | module.exports = class Base {
|
10 |
|
11 | static init (nodeModule) {
|
12 | if (nodeModule) {
|
13 | ClassHelper.defineClassProperty(this, 'CLASS_FILE', nodeModule.filename);
|
14 | ClassHelper.defineClassProperty(this, 'CLASS_DIRECTORY', path.dirname(nodeModule.filename));
|
15 | }
|
16 | ClassHelper.defineConstantClassProperties(this);
|
17 | return this;
|
18 | }
|
19 |
|
20 | static wrapClassMessage (message) {
|
21 | return `${this.name}: ${message}`;
|
22 | }
|
23 |
|
24 | constructor (config) {
|
25 | if (config) {
|
26 | Object.assign(this, config);
|
27 | }
|
28 | }
|
29 |
|
30 | getClass () {
|
31 | return this.module.getClass(...arguments);
|
32 | }
|
33 |
|
34 | spawnSelf (params) {
|
35 | return this.spawn(this.constructor, params);
|
36 | }
|
37 |
|
38 | spawn (config, params) {
|
39 | if (!params) {
|
40 | params = {module: this.module};
|
41 | } else if (params.module === undefined) {
|
42 | params.module = this.module;
|
43 | }
|
44 | return ClassHelper.spawn(config, params);
|
45 | }
|
46 |
|
47 | wrapClassMessage (message) {
|
48 | return this.constructor.wrapClassMessage(message);
|
49 | }
|
50 | };
|
51 |
|
52 |
|
53 | RegExp.prototype.toJSON = RegExp.prototype.toString; |
\ | No newline at end of file |