feat: Hook based overrides
This commit is contained in:
parent
bfc10e6034
commit
eced5f2ec4
3 changed files with 44 additions and 2 deletions
|
|
@ -1,4 +1,4 @@
|
|||
local hooks, M = {}, {};
|
||||
local hooks, overrides, M = {}, {}, {};
|
||||
local allowed_hooks = {
|
||||
"install_plugins",
|
||||
"setup_mappings",
|
||||
|
|
@ -35,4 +35,35 @@ M.run = function(name, args)
|
|||
end
|
||||
end
|
||||
|
||||
M.createOverrides = function(module)
|
||||
local O = {};
|
||||
|
||||
O.get = function(name, default)
|
||||
local current = default;
|
||||
if overrides[module] and overrides[module][name] then
|
||||
if type(overrides[module][name]) == "function" then
|
||||
current = overrides[module][name]
|
||||
elseif type(overrides[module][name]) == "table" then
|
||||
for _, override in pairs(overrides[module][name]) do
|
||||
current = override(current)
|
||||
end
|
||||
end
|
||||
end
|
||||
return current;
|
||||
end
|
||||
|
||||
return O;
|
||||
end
|
||||
|
||||
M.override = function(module, name, overwrite)
|
||||
if overrides[module] == nil then
|
||||
overrides[module] = {};
|
||||
end
|
||||
if overrides[module][name] == nil then
|
||||
overrides[module][name] = {};
|
||||
end
|
||||
table.insert(overrides[module][name], overwrite)
|
||||
end
|
||||
|
||||
|
||||
return M;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue