Add name shortcut for ConfigGroup instances

Add .name shortcut to get the groupName class property of config group
instances.
This commit is contained in:
Hornwitser committed 2020-05-31 14:16:06 +02:00
1 parent 67ca8dcc4d
commit 8c9daff0bb
2 files changed
+21 -4

No files matched your search

+13 -4
View File
@@ -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,
};
}
+8
View File
@@ -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();