22 lines
624 B
Python
22 lines
624 B
Python
from app.plugins.base import BaseAction
|
|
|
|
|
|
class ActionRegistry:
|
|
def __init__(self) -> None:
|
|
self._actions: dict[str, BaseAction] = {}
|
|
|
|
def register(self, action: BaseAction) -> None:
|
|
self._actions[action.name] = action
|
|
|
|
def get(self, name: str) -> BaseAction | None:
|
|
return self._actions.get(name)
|
|
|
|
def all(self) -> list[BaseAction]:
|
|
return list(self._actions.values())
|
|
|
|
def for_category(self, category: str) -> list[BaseAction]:
|
|
return [a for a in self._actions.values() if a.is_compatible(category)]
|
|
|
|
|
|
# Module-level singleton
|
|
action_registry = ActionRegistry()
|