mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-23 16:23:12 +09:00
Add name shortcut for ConfigGroup instances
Add .name shortcut to get the groupName class property of config group instances.
This commit is contained in:
1 parent
67ca8dcc4d
commit
8c9daff0bb
2 files changed
+21
-4
No files matched your search
+13
-4
@@ -112,7 +112,7 @@ class Config extends events.EventEmitter {
|
|||||||
|
|
||||||
let group = new GroupClass();
|
let group = new GroupClass();
|
||||||
await group.load(this, serializedGroup);
|
await group.load(this, serializedGroup);
|
||||||
this._groups.set(GroupClass.groupName, group);
|
this._groups.set(group.name, group);
|
||||||
}
|
}
|
||||||
|
|
||||||
await this.init();
|
await this.init();
|
||||||
@@ -301,6 +301,15 @@ class ConfigGroup {
|
|||||||
await this.init(config);
|
await this.init(config);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Name of the group
|
||||||
|
*
|
||||||
|
* Shortcut for `group.constructor.groupName`
|
||||||
|
*/
|
||||||
|
get name() {
|
||||||
|
return this.constructor.groupName;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get value for field
|
* Get value for field
|
||||||
*/
|
*/
|
||||||
@@ -384,8 +393,8 @@ class ConfigGroup {
|
|||||||
throw new Error(`Expected object, not ${basicType(serializedGroup)} for ConfigGroup`);
|
throw new Error(`Expected object, not ${basicType(serializedGroup)} for ConfigGroup`);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (serializedGroup.name !== this.constructor.groupName) {
|
if (serializedGroup.name !== this.name) {
|
||||||
throw new Error(`Expected group name ${this.constructor.groupName}, not ${serializedGroup.name}`);
|
throw new Error(`Expected group name ${this.name}, not ${serializedGroup.name}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (basicType(serializedGroup.fields) !== "object") {
|
if (basicType(serializedGroup.fields) !== "object") {
|
||||||
@@ -435,7 +444,7 @@ class ConfigGroup {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
name: this.constructor.groupName,
|
name: this.name,
|
||||||
fields,
|
fields,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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() {
|
describe(".serialize()", function() {
|
||||||
it("should serialize a basic group", async function() {
|
it("should serialize a basic group", async function() {
|
||||||
let testInstance = new TestGroup();
|
let testInstance = new TestGroup();
|
||||||
|
|||||||
Reference in new issue
Block a user