Coverage for src/lexigram/web/contributors/registry.py: 67%
12 statements
« prev ^ index » next coverage.py v7.15.4, created at 2026-08-25 04:37 +0800
« prev ^ index » next coverage.py v7.15.4, created at 2026-08-25 04:37 +0800
1"""Web contributor registry.
3Registry for tracking discovered web contributors that provide controllers
4and middleware to the web provider.
5"""
7from __future__ import annotations
9from lexigram.contracts.web import WebContributorProtocol
12class WebContributorRegistry:
13 """Registry for web contributors discovered via entry-points.
15 The web provider discovers contributors during registration phase
16 and stores them in this registry for tracking and debugging purposes.
17 """
19 def __init__(self) -> None:
20 """Initialize an empty registry."""
21 self._contributors: dict[str, WebContributorProtocol] = {}
23 def register(self, contributor: WebContributorProtocol) -> None:
24 """Register a web contributor.
26 Args:
27 contributor: The contributor instance to register.
28 """
29 self._contributors[contributor.contributor_id] = contributor
31 def get(self, contributor_id: str) -> WebContributorProtocol | None:
32 """Get a contributor by ID.
34 Args:
35 contributor_id: The unique contributor identifier.
37 Returns:
38 The contributor instance or None if not found.
39 """
40 return self._contributors.get(contributor_id)
42 def get_all(self) -> list[WebContributorProtocol]:
43 """Get all registered contributors.
45 Returns:
46 List of all registered contributors in registration order.
47 """
48 return list(self._contributors.values())
51__all__ = ["WebContributorRegistry"]