diff --git a/lib/config/classes.js b/lib/config/classes.js index 4c5c0351..14ee1b8b 100644 --- a/lib/config/classes.js +++ b/lib/config/classes.js @@ -112,7 +112,7 @@ class Config extends events.EventEmitter { let group = new GroupClass(); await group.load(this, serializedGroup); - this._groups.set(GroupClass.groupName, group); + this._groups.set(group.name, group); } await this.init(); @@ -301,6 +301,15 @@ class ConfigGroup { await this.init(config); } + /** + * Name of the group + * + * Shortcut for `group.constructor.groupName` + */ + get name() { + return this.constructor.groupName; + } + /** * Get value for field */ @@ -384,8 +393,8 @@ class ConfigGroup { throw new Error(`Expected object, not ${basicType(serializedGroup)} for ConfigGroup`); } - if (serializedGroup.name !== this.constructor.groupName) { - throw new Error(`Expected group name ${this.constructor.groupName}, not ${serializedGroup.name}`); + if (serializedGroup.name !== this.name) { + throw new Error(`Expected group name ${this.name}, not ${serializedGroup.name}`); } if (basicType(serializedGroup.fields) !== "object") { @@ -435,7 +444,7 @@ class ConfigGroup { } return { - name: this.constructor.groupName, + name: this.name, fields, }; } diff --git a/test/lib/config/classes.js b/test/lib/config/classes.js index 7f7c862c..614a020b 100644 --- a/test/lib/config/classes.js +++ b/test/lib/config/classes.js @@ -156,6 +156,14 @@ describe("lib/config/classes", function() { }); }); + describe("get name", function() { + it("should give the name of the group", async function() { + let testInstance = new TestGroup(); + await testInstance.init(); + assert.equal(testInstance.name, "test_group"); + }); + }); + describe(".serialize()", function() { it("should serialize a basic group", async function() { let testInstance = new TestGroup();