Registry
A registry is a centralized collection of validated data.
INFO
The type T is the type of the items in the registry.
Functions
new
Registry.new() → ()
Create a new registry. The parent paramater if passed will just call Registry.loadFromParent, pass nil to skip this.
You can pass a validationFunction which gets asserted on every object to ensure its the correct type.
Finally a processFunction can be passed which gets run on every object and can convert objects into something else, for
example you could create a processFunction like this:
Registry.new(script.Parent.ItemModels, nil, function(instance: Model)
local item = {}
for k, v in instance:GetAttributes() do
items[k] = v
end
item.model = instance
return item
end)
INFO
If your data is stored as module scripts this will automatically pick that up and require the module scripts for you. However if you have a folder with mixed instance (e.g. ModuleScripts and Folders) if will not work properly and require the module scripts but add the raw instacne folders themselves (if no validationFunction is present).
add
Registry:add(name: string,obj: T) → ()Adds something to the registry.
Errors
| Type | Description |
|---|---|
| "Object did not pass validation function" | The `obj` passed doesnt pass the `validationFunction` after the `processFunction` |
loadFromParent
Load all the instacnes from the given instance. Note that this only calls :GetChildren() on the instance.
doesExist
Registry:doesExist(name: string) → booleanCheck if an item with the name name exists in the repository.
getItem
Registry:getItem(name: string) → TGets an item with the name name from the registry, if it doesn't exist this function will error.
Errors
| Type | Description |
|---|---|
| "Object with the name "{name}" doesn't exist in the repository." | No object with the name `name` exist in the repository. You should use "doesExist" if you are cannot guarantee if an object will exist. |