Coverage for src / mesh / models / roles / visitor.py: 93%
14 statements
« prev ^ index » next coverage.py v7.13.1, created at 2026-05-04 12:41 +0000
« prev ^ index » next coverage.py v7.13.1, created at 2026-05-04 12:41 +0000
1from abc import ABC, abstractmethod
2from typing import TYPE_CHECKING, Generic, TypeVar
4if TYPE_CHECKING:
5 from mesh.models.roles.base_role import Role
7VisitorRT = TypeVar("VisitorRT")
10class RoleVisitor(ABC, Generic[VisitorRT]):
11 role: "Role"
13 def __init__(self, role: "Role", *args, **kwargs):
14 self.role = role
15 super().__init__(*args, **kwargs)
17 def visit(self, *args, **kwargs) -> VisitorRT:
18 function_name = f"visit_{self.role.code()}"
19 ftor = getattr(self, function_name, None)
20 if not callable(ftor):
21 raise LookupError(f"RoleVisitor does not implements {function_name}")
22 return ftor(*args, **kwargs) # type:ignore
24 @abstractmethod
25 def visit_author(self, *args, **kwargs) -> VisitorRT: ...
27 @abstractmethod
28 def visit_editor(self, *args, **kwargs) -> VisitorRT: ...
30 @abstractmethod
31 def visit_journal_manager(self, *args, **kwargs) -> VisitorRT: ...
33 @abstractmethod
34 def visit_reviewer(self, *args, **kwargs) -> VisitorRT: ...