__init__.py¶
Info¶
- Parent directory
isshub/domain/contexts/code_repository/repositories/repository/
- Last update
Last source¶
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 | """Package defining the repository for the :obj:`.Repository` entity."""
import abc
from typing import Iterable
from .....utils.repository import AbstractInMemoryRepository, AbstractRepository
from ...entities import Namespace, Repository
class AbstractRepositoryRepository(
AbstractRepository[Repository], entity_class=Repository
):
"""Base repository for the :obj:`.Repository` entity."""
@abc.abstractmethod
def for_namespace(self, namespace: Namespace) -> Iterable[Repository]:
"""Iterate on repositories found in the given `namespace`.
Parameters
----------
namespace : Namespace
The namespace for which we want to find the repositories
Returns
-------
Iterable[Repository]
An iterable of the repositories found in the `namespace`
"""
class InMemoryRepositoryRepository(
AbstractInMemoryRepository, AbstractRepositoryRepository
):
"""Repository to handle :obj:`.Repository` entities in memory."""
def add(self, entity: Repository) -> Repository:
"""Add the given Repository `entity` in the repository.
For the parameters, see :obj:`AbstractRepository.add`.
Returns
-------
Repository
The added Repository
Raises
------
self.UniquenessError
- If a repository with the same identifier as the given one already exists.
- If a repository with the same name and namespace as the given one already exists.
"""
if any(
repository
for repository in self.for_namespace(entity.namespace)
if repository.name == entity.name
):
raise self.UniquenessError(
f"One already exists with name={entity.name} and namespace={entity.namespace}"
)
return super().add(entity)
def for_namespace(self, namespace: Namespace) -> Iterable[Repository]:
"""Iterate on repositories found in the given `namespace`.
For the parameters, see :obj:`AbstractRepositoryRepository.for_namespace`
Returns
-------
Iterable[Repository]
An iterable of the repositories found in the `namespace`
"""
return (entity for entity in self._collection if entity.namespace == namespace)
|
Changes¶
feat(repository): Add domain repositories¶
- Commit
- Hash
- Date
2020-10-06 17:30:45 +0200
- Type
Added
- Stats
+75 -0
@@ -0,0 +1,75 @@
+"""Package defining the repository for the :obj:`.Repository` entity."""
+
+import abc
+from typing import Iterable
+
+from .....utils.repository import AbstractInMemoryRepository, AbstractRepository
+from ...entities import Namespace, Repository
+
+
+class AbstractRepositoryRepository(
+ AbstractRepository[Repository], entity_class=Repository
+):
+ """Base repository for the :obj:`.Repository` entity."""
+
+ @abc.abstractmethod
+ def for_namespace(self, namespace: Namespace) -> Iterable[Repository]:
+ """Iterate on repositories found in the given `namespace`.
+
+ Parameters
+ ----------
+ namespace : Namespace
+ The namespace for which we want to find the repositories
+
+ Returns
+ -------
+ Iterable[Repository]
+ An iterable of the repositories found in the `namespace`
+
+ """
+
+
+class InMemoryRepositoryRepository(
+ AbstractInMemoryRepository, AbstractRepositoryRepository
+):
+ """Repository to handle :obj:`.Repository` entities in memory."""
+
+ def add(self, entity: Repository) -> Repository:
+ """Add the given Repository `entity` in the repository.
+
+ For the parameters, see :obj:`AbstractRepository.add`.
+
+ Returns
+ -------
+ Repository
+ The added Repository
+
+ Raises
+ ------
+ self.UniquenessError
+ - If a repository with the same identifier as the given one already exists.
+ - If a repository with the same name and namespace as the given one already exists.
+
+ """
+ if any(
+ repository
+ for repository in self.for_namespace(entity.namespace)
+ if repository.name == entity.name
+ ):
+ raise self.UniquenessError(
+ f"One already exists with name={entity.name} and namespace={entity.namespace}"
+ )
+ return super().add(entity)
+
+ def for_namespace(self, namespace: Namespace) -> Iterable[Repository]:
+ """Iterate on repositories found in the given `namespace`.
+
+ For the parameters, see :obj:`AbstractRepositoryRepository.for_namespace`
+
+ Returns
+ -------
+ Iterable[Repository]
+ An iterable of the repositories found in the `namespace`
+
+ """
+ return (entity for entity in self._collection if entity.namespace == namespace)