util.roles: Implement a serialization preparation metamethod

Should be able to roundtrip trough serialization. Also nice for debug
and logging purposes where you might want more details than what the
__tostring method provides.
This commit is contained in:
Kim Alvefur 2023-03-26 13:13:31 +02:00
parent 196117c3f2
commit 5427c2472d

View file

@ -73,6 +73,19 @@ local function new(base_config, overrides)
return setmetatable(new_role, role_mt);
end
function role_mt:__freeze()
local t = {
id = self.id;
name = self.name;
description = self.description;
default = self.default;
priority = self.priority;
inherits = self.inherits;
permissions = self[permissions_key];
};
return t;
end
function role_methods:clone(overrides)
return new(self, overrides);
end