value-object-pattern 0.1.0__py3-none-any.whl → 0.3.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- value_object_pattern/__init__.py +3 -2
- value_object_pattern/models/__init__.py +5 -1
- value_object_pattern/models/enumeration_value_object.py +169 -0
- value_object_pattern/usables/identifiers/countries/__init__.py +0 -0
- value_object_pattern/usables/identifiers/{country_ids → countries}/spain/dni_value_object.py +16 -3
- value_object_pattern/usables/identifiers/string_uuid_value_object.py +15 -4
- value_object_pattern/usables/identifiers/uuid_value_object.py +14 -1
- value_object_pattern/usables/internet/__init__.py +0 -12
- value_object_pattern/usables/primitives/boolean/boolean_value_object.py +15 -1
- value_object_pattern/usables/primitives/boolean/false_value_object.py +15 -1
- value_object_pattern/usables/primitives/boolean/true_value_object.py +15 -1
- value_object_pattern/usables/primitives/bytes/bytes_value_object.py +15 -1
- value_object_pattern/usables/primitives/float/float_value_object.py +15 -1
- value_object_pattern/usables/primitives/float/negative_float_value_object.py +15 -1
- value_object_pattern/usables/primitives/float/positive_float_value_object.py +15 -1
- value_object_pattern/usables/primitives/integer/even_integer_value_object.py +15 -1
- value_object_pattern/usables/primitives/integer/integer_value_object.py +15 -1
- value_object_pattern/usables/primitives/integer/negative_integer_value_object.py +15 -1
- value_object_pattern/usables/primitives/integer/odd_integer_value_object.py +15 -1
- value_object_pattern/usables/primitives/integer/positive_integer_value_object.py +15 -1
- value_object_pattern/usables/primitives/string/alpha_value_object.py +15 -1
- value_object_pattern/usables/primitives/string/alphanumeric_value_object.py +15 -1
- value_object_pattern/usables/primitives/string/digit_value_object.py +15 -1
- value_object_pattern/usables/primitives/string/lowercase_string_value_object.py +15 -1
- value_object_pattern/usables/primitives/string/non_empty_string_value_object.py +15 -1
- value_object_pattern/usables/primitives/string/printable_string_value_object.py +15 -1
- value_object_pattern/usables/primitives/string/string_value_object.py +15 -1
- value_object_pattern/usables/primitives/string/trimmed_string_value_object.py +15 -1
- value_object_pattern/usables/primitives/string/uppercase_string_value_object.py +15 -1
- {value_object_pattern-0.1.0.dist-info → value_object_pattern-0.3.0.dist-info}/METADATA +1 -1
- {value_object_pattern-0.1.0.dist-info → value_object_pattern-0.3.0.dist-info}/RECORD +34 -39
- value_object_pattern/usables/identifiers/country_ids/__init__.py +0 -3
- value_object_pattern/usables/internet/api_keys/__init__.py +0 -13
- value_object_pattern/usables/internet/api_keys/aws_access_key_id_value_object.py +0 -40
- value_object_pattern/usables/internet/api_keys/aws_secret_access_key_value_object.py +0 -40
- value_object_pattern/usables/internet/api_keys/github_personal_access_token_value_object.py +0 -41
- value_object_pattern/usables/internet/api_keys/openai_api_key_value_object.py +0 -40
- value_object_pattern/usables/internet/api_keys/resend_api_key_value_object.py +0 -40
- /value_object_pattern/usables/identifiers/{country_ids → countries}/spain/__init__.py +0 -0
- {value_object_pattern-0.1.0.dist-info → value_object_pattern-0.3.0.dist-info}/WHEEL +0 -0
- {value_object_pattern-0.1.0.dist-info → value_object_pattern-0.3.0.dist-info}/licenses/LICENSE.md +0 -0
value_object_pattern/__init__.py
CHANGED
@@ -1,9 +1,10 @@
|
|
1
|
-
__version__ = '0.
|
1
|
+
__version__ = '0.3.0'
|
2
2
|
|
3
3
|
from .decorators import process, validation
|
4
|
-
from .models import ValueObject
|
4
|
+
from .models import EnumerationValueObject, ValueObject
|
5
5
|
|
6
6
|
__all__ = (
|
7
|
+
'EnumerationValueObject',
|
7
8
|
'ValueObject',
|
8
9
|
'process',
|
9
10
|
'validation',
|
@@ -0,0 +1,169 @@
|
|
1
|
+
"""
|
2
|
+
EnumerationValueObject module.
|
3
|
+
"""
|
4
|
+
|
5
|
+
from enum import Enum
|
6
|
+
from inspect import isclass
|
7
|
+
from sys import version_info
|
8
|
+
from typing import Any, Generic, TypeVar, get_args, get_origin
|
9
|
+
|
10
|
+
if version_info >= (3, 12):
|
11
|
+
from typing import override # pragma: no cover
|
12
|
+
else:
|
13
|
+
from typing_extensions import override # pragma: no cover
|
14
|
+
|
15
|
+
from value_object_pattern.decorators import process, validation
|
16
|
+
from value_object_pattern.models.value_object import ValueObject
|
17
|
+
|
18
|
+
E = TypeVar('E', bound=Enum)
|
19
|
+
|
20
|
+
|
21
|
+
class EnumerationValueObject(ValueObject[str | E], Generic[E]):
|
22
|
+
"""
|
23
|
+
EnumerationValueObject is a value object that ensures the provided value is from an enumeration.
|
24
|
+
|
25
|
+
Example:
|
26
|
+
```python
|
27
|
+
from enum import Enum, unique
|
28
|
+
|
29
|
+
from value_object_pattern import EnumerationValueObject
|
30
|
+
|
31
|
+
|
32
|
+
@unique
|
33
|
+
class ColorEnumeration(Enum):
|
34
|
+
RED = 1
|
35
|
+
GREEN = 2
|
36
|
+
BLUE = 3
|
37
|
+
|
38
|
+
|
39
|
+
class ColorValueObject(EnumerationValueObject[ColorEnumeration]):
|
40
|
+
pass
|
41
|
+
|
42
|
+
|
43
|
+
red = ColorValueObject(value=ColorEnumeration.RED)
|
44
|
+
green = ColorValueObject(value='GREEN')
|
45
|
+
print(repr(red), repr(green))
|
46
|
+
# >>> ColorValueObject(value=ColorEnumeration.RED) ColorValueObject(value=ColorEnumeration.GREEN)
|
47
|
+
```
|
48
|
+
"""
|
49
|
+
|
50
|
+
_enumeration: type[E]
|
51
|
+
|
52
|
+
@override
|
53
|
+
def __init_subclass__(cls, **kwargs: Any) -> None:
|
54
|
+
"""
|
55
|
+
Initializes the class.
|
56
|
+
|
57
|
+
Args:
|
58
|
+
**kwargs (Any): Keyword arguments.
|
59
|
+
|
60
|
+
Raises:
|
61
|
+
TypeError: If the class parameter is not an Enum subclass.
|
62
|
+
TypeError: If the class is not parameterized.
|
63
|
+
"""
|
64
|
+
super().__init_subclass__(**kwargs)
|
65
|
+
|
66
|
+
for base in getattr(cls, '__orig_bases__', ()):
|
67
|
+
if get_origin(tp=base) is EnumerationValueObject:
|
68
|
+
enumeration, *_ = get_args(tp=base)
|
69
|
+
|
70
|
+
if not (isclass(object=enumeration) and issubclass(enumeration, Enum)):
|
71
|
+
raise TypeError(f'EnumerationValueObject[...] <<<{enumeration}>>> must be an Enum subclass. Got <<<{type(enumeration).__name__}>>> type.') # noqa: E501 # fmt: skip
|
72
|
+
|
73
|
+
cls._enumeration = enumeration
|
74
|
+
return
|
75
|
+
|
76
|
+
raise TypeError('EnumerationValueObject must be parameterized, e.g. "class ColorValueObject(EnumerationValueObject[ColorEnumeration])".') # noqa: E501 # fmt: skip
|
77
|
+
|
78
|
+
@override
|
79
|
+
def __repr__(self) -> str:
|
80
|
+
"""
|
81
|
+
Returns a detailed string representation of the value object.
|
82
|
+
|
83
|
+
Returns:
|
84
|
+
str: A string representation of the value object in the format 'ClassName(value=value)'.
|
85
|
+
|
86
|
+
Example:
|
87
|
+
```python
|
88
|
+
from enum import Enum, unique
|
89
|
+
|
90
|
+
from value_object_pattern import EnumerationValueObject
|
91
|
+
|
92
|
+
|
93
|
+
@unique
|
94
|
+
class ColorEnumeration(Enum):
|
95
|
+
RED = 1
|
96
|
+
GREEN = 2
|
97
|
+
BLUE = 3
|
98
|
+
|
99
|
+
|
100
|
+
class ColorValueObject(EnumerationValueObject[ColorEnumeration]):
|
101
|
+
pass
|
102
|
+
|
103
|
+
|
104
|
+
red = ColorValueObject(value=ColorEnumeration.RED)
|
105
|
+
print(repr(red))
|
106
|
+
# >>> ColorValueObject(value=ColorEnumeration.RED)
|
107
|
+
```
|
108
|
+
"""
|
109
|
+
return f'{self.__class__.__name__}(value={self.value.__class__.__name__}.{self.value.name})'
|
110
|
+
|
111
|
+
@process(order=0)
|
112
|
+
def _ensure_value_is_stored_as_enumeration(self, value: str | E) -> E:
|
113
|
+
"""
|
114
|
+
Ensures the value object `value` is stored as an enumeration.
|
115
|
+
|
116
|
+
Args:
|
117
|
+
value (str | E): The provided value. It can be the name of the member or the member itself.
|
118
|
+
|
119
|
+
Returns:
|
120
|
+
E: The processed value.
|
121
|
+
"""
|
122
|
+
if isinstance(value, str):
|
123
|
+
return self._enumeration[value.upper()]
|
124
|
+
|
125
|
+
return value
|
126
|
+
|
127
|
+
@validation(order=0)
|
128
|
+
def _ensure_value_is_from_enumeration(self, value: str | E) -> None:
|
129
|
+
"""
|
130
|
+
Ensures the value object `value` is from the enumeration.
|
131
|
+
|
132
|
+
Args:
|
133
|
+
value (str | E): The provided value. It can be the name of the member or the member itself.
|
134
|
+
|
135
|
+
Raises:
|
136
|
+
TypeError: If the `value` is not from the enumeration.
|
137
|
+
"""
|
138
|
+
if isinstance(value, self._enumeration):
|
139
|
+
return
|
140
|
+
|
141
|
+
if isinstance(value, str) and value in self._enumeration.__members__:
|
142
|
+
return
|
143
|
+
|
144
|
+
raise TypeError(f'EnumerationValueObject value <<<{value}>>> must be from the enumeration <<<{self._title}>>>.') # noqa: E501 # fmt: skip
|
145
|
+
|
146
|
+
@override
|
147
|
+
@property
|
148
|
+
def value(self) -> E:
|
149
|
+
"""
|
150
|
+
Returns the value object value.
|
151
|
+
|
152
|
+
Returns:
|
153
|
+
E: The value object value.
|
154
|
+
|
155
|
+
Example:
|
156
|
+
```python
|
157
|
+
from value_object_pattern import ValueObject
|
158
|
+
|
159
|
+
|
160
|
+
class IntegerValueObject(ValueObject[int]):
|
161
|
+
pass
|
162
|
+
|
163
|
+
|
164
|
+
integer = IntegerValueObject(value=10)
|
165
|
+
print(integer.value)
|
166
|
+
# >>> 10
|
167
|
+
```
|
168
|
+
"""
|
169
|
+
return self._value # type: ignore[return-value]
|
File without changes
|
value_object_pattern/usables/identifiers/{country_ids → countries}/spain/dni_value_object.py
RENAMED
@@ -3,6 +3,7 @@ DniValueObject value object.
|
|
3
3
|
"""
|
4
4
|
|
5
5
|
from re import Pattern, compile as re_compile
|
6
|
+
from typing import NoReturn
|
6
7
|
|
7
8
|
from value_object_pattern.decorators import process, validation
|
8
9
|
from value_object_pattern.usables import NotEmptyStringValueObject, TrimmedStringValueObject
|
@@ -16,7 +17,7 @@ class DniValueObject(NotEmptyStringValueObject, TrimmedStringValueObject):
|
|
16
17
|
|
17
18
|
Example:
|
18
19
|
```python
|
19
|
-
from value_object_pattern.usables.identifiers.
|
20
|
+
from value_object_pattern.usables.identifiers.countries.spain import DniValueObject
|
20
21
|
|
21
22
|
dni = DniValueObject(value='87654321X')
|
22
23
|
|
@@ -54,10 +55,22 @@ class DniValueObject(NotEmptyStringValueObject, TrimmedStringValueObject):
|
|
54
55
|
"""
|
55
56
|
match = self.__DNI_VALUE_OBJECT_REGEX.fullmatch(string=value)
|
56
57
|
if not match:
|
57
|
-
|
58
|
+
self._raise_value_is_not_dni(value=value)
|
58
59
|
|
59
60
|
number, letter = match.groups()
|
60
61
|
|
61
62
|
expected_letter = self.__DNI_VALUE_OBJECT_LETTERS[int(number) % 23]
|
62
63
|
if letter.upper() != expected_letter:
|
63
|
-
|
64
|
+
self._raise_value_is_not_dni(value=value)
|
65
|
+
|
66
|
+
def _raise_value_is_not_dni(self, value: str) -> NoReturn:
|
67
|
+
"""
|
68
|
+
Raises a ValueError if the value object `value` is not a Spanish DNI.
|
69
|
+
|
70
|
+
Args:
|
71
|
+
value (str): The provided value.
|
72
|
+
|
73
|
+
Raises:
|
74
|
+
ValueError: If the `value` is not a Spanish DNI.
|
75
|
+
"""
|
76
|
+
raise ValueError(f'DniValueObject value <<<{value}>>> is not a valid Spanish DNI.')
|
@@ -2,8 +2,7 @@
|
|
2
2
|
StringUuidValueObject value object.
|
3
3
|
"""
|
4
4
|
|
5
|
-
from
|
6
|
-
|
5
|
+
from typing import NoReturn
|
7
6
|
from uuid import UUID
|
8
7
|
|
9
8
|
from value_object_pattern.decorators import process, validation
|
@@ -52,5 +51,17 @@ class StringUuidValueObject(NotEmptyStringValueObject, TrimmedStringValueObject)
|
|
52
51
|
try:
|
53
52
|
UUID(hex=value)
|
54
53
|
|
55
|
-
except ValueError
|
56
|
-
|
54
|
+
except ValueError:
|
55
|
+
self._raise_value_is_not_uuid(value=value)
|
56
|
+
|
57
|
+
def _raise_value_is_not_uuid(self, value: str) -> NoReturn:
|
58
|
+
"""
|
59
|
+
Raises a ValueError if the value object `value` is not a UUID.
|
60
|
+
|
61
|
+
Args:
|
62
|
+
value (str): The provided value.
|
63
|
+
|
64
|
+
Raises:
|
65
|
+
ValueError: If the `value` is not a UUID.
|
66
|
+
"""
|
67
|
+
raise ValueError(f'StringUuidValueObject value <<<{value}>>> is not a valid UUID.')
|
@@ -2,6 +2,7 @@
|
|
2
2
|
UuidValueObject value object.
|
3
3
|
"""
|
4
4
|
|
5
|
+
from typing import Any, NoReturn
|
5
6
|
from uuid import UUID
|
6
7
|
|
7
8
|
from value_object_pattern.decorators import validation
|
@@ -37,4 +38,16 @@ class UuidValueObject(ValueObject[UUID]):
|
|
37
38
|
TypeError: If the `value` is not a UUID.
|
38
39
|
"""
|
39
40
|
if type(value) is not UUID:
|
40
|
-
|
41
|
+
self._raise_value_is_not_uuid(value=value)
|
42
|
+
|
43
|
+
def _raise_value_is_not_uuid(self, value: Any) -> NoReturn:
|
44
|
+
"""
|
45
|
+
Raises a TypeError if the value object `value` is not a UUID.
|
46
|
+
|
47
|
+
Args:
|
48
|
+
value (Any): The provided value.
|
49
|
+
|
50
|
+
Raises:
|
51
|
+
TypeError: If the `value` is not a UUID.
|
52
|
+
"""
|
53
|
+
raise TypeError(f'UuidValueObject value <<<{value}>>> must be a UUID. Got <<<{type(value).__name__}>>> type.')
|
@@ -1,10 +1,3 @@
|
|
1
|
-
from .api_keys import (
|
2
|
-
AwsAccessKeyValueObject,
|
3
|
-
AwsSecretAccessKeyValueObject,
|
4
|
-
GitHubPersonalAccessTokenValueObject,
|
5
|
-
OpenaiApiKeyValueObject,
|
6
|
-
ResendApiKeyValueObject,
|
7
|
-
)
|
8
1
|
from .aws_cloud_region_value_object import AwsCloudRegionValueObject
|
9
2
|
from .domain_value_object import DomainValueObject
|
10
3
|
from .host_value_object import HostValueObject
|
@@ -17,11 +10,8 @@ from .port_value_object import PortValueObject
|
|
17
10
|
from .uri import HttpHttpsUrlValueObject, HttpUrlValueObject, HttpsUrlValueObject, UrlValueObject
|
18
11
|
|
19
12
|
__all__ = (
|
20
|
-
'AwsAccessKeyValueObject',
|
21
13
|
'AwsCloudRegionValueObject',
|
22
|
-
'AwsSecretAccessKeyValueObject',
|
23
14
|
'DomainValueObject',
|
24
|
-
'GitHubPersonalAccessTokenValueObject',
|
25
15
|
'HostValueObject',
|
26
16
|
'HttpHttpsUrlValueObject',
|
27
17
|
'HttpUrlValueObject',
|
@@ -31,8 +21,6 @@ __all__ = (
|
|
31
21
|
'Ipv6AddressValueObject',
|
32
22
|
'Ipv6NetworkValueObject',
|
33
23
|
'MacAddressValueObject',
|
34
|
-
'OpenaiApiKeyValueObject',
|
35
24
|
'PortValueObject',
|
36
|
-
'ResendApiKeyValueObject',
|
37
25
|
'UrlValueObject',
|
38
26
|
)
|
@@ -2,6 +2,8 @@
|
|
2
2
|
BooleanValueObject value object.
|
3
3
|
"""
|
4
4
|
|
5
|
+
from typing import Any, NoReturn
|
6
|
+
|
5
7
|
from value_object_pattern.decorators import validation
|
6
8
|
from value_object_pattern.models import ValueObject
|
7
9
|
|
@@ -33,4 +35,16 @@ class BooleanValueObject(ValueObject[bool]):
|
|
33
35
|
TypeError: If the `value` is not a boolean.
|
34
36
|
"""
|
35
37
|
if type(value) is not bool:
|
36
|
-
|
38
|
+
self._raise_value_is_not_boolean(value=value)
|
39
|
+
|
40
|
+
def _raise_value_is_not_boolean(self, value: Any) -> NoReturn:
|
41
|
+
"""
|
42
|
+
Raises a TypeError if the value object `value` is not a boolean.
|
43
|
+
|
44
|
+
Args:
|
45
|
+
value (Any): The provided value.
|
46
|
+
|
47
|
+
Raises:
|
48
|
+
TypeError: If the `value` is not a boolean.
|
49
|
+
"""
|
50
|
+
raise TypeError(f'BooleanValueObject value <<<{value}>>> must be a boolean. Got <<<{type(value).__name__}>>> type.') # noqa: E501 # fmt: skip
|
@@ -2,6 +2,8 @@
|
|
2
2
|
FalseValueObject value object.
|
3
3
|
"""
|
4
4
|
|
5
|
+
from typing import NoReturn
|
6
|
+
|
5
7
|
from value_object_pattern.decorators import validation
|
6
8
|
|
7
9
|
from .boolean_value_object import BooleanValueObject
|
@@ -34,4 +36,16 @@ class FalseValueObject(BooleanValueObject):
|
|
34
36
|
ValueError: If the `value` is not false.
|
35
37
|
"""
|
36
38
|
if value:
|
37
|
-
|
39
|
+
self._raise_value_is_not_false(value=value)
|
40
|
+
|
41
|
+
def _raise_value_is_not_false(self, value: bool) -> NoReturn:
|
42
|
+
"""
|
43
|
+
Raises a ValueError if the value object `value` is not false.
|
44
|
+
|
45
|
+
Args:
|
46
|
+
value (bool): The provided value.
|
47
|
+
|
48
|
+
Raises:
|
49
|
+
ValueError: If the `value` is not false.
|
50
|
+
"""
|
51
|
+
raise ValueError(f'FalseValueObject value <<<{value}>>> must be false.')
|
@@ -2,6 +2,8 @@
|
|
2
2
|
TrueValueObject value object.
|
3
3
|
"""
|
4
4
|
|
5
|
+
from typing import NoReturn
|
6
|
+
|
5
7
|
from value_object_pattern.decorators import validation
|
6
8
|
|
7
9
|
from .boolean_value_object import BooleanValueObject
|
@@ -34,4 +36,16 @@ class TrueValueObject(BooleanValueObject):
|
|
34
36
|
ValueError: If the `value` is not true.
|
35
37
|
"""
|
36
38
|
if not value:
|
37
|
-
|
39
|
+
self._raise_value_is_not_true(value=value)
|
40
|
+
|
41
|
+
def _raise_value_is_not_true(self, value: bool) -> NoReturn:
|
42
|
+
"""
|
43
|
+
Raises a ValueError if the value object `value` is not true.
|
44
|
+
|
45
|
+
Args:
|
46
|
+
value (bool): The provided value.
|
47
|
+
|
48
|
+
Raises:
|
49
|
+
ValueError: If the `value` is not true.
|
50
|
+
"""
|
51
|
+
raise ValueError(f'TrueValueObject value <<<{value}>>> must be true.')
|
@@ -2,6 +2,8 @@
|
|
2
2
|
BytesValueObject value object.
|
3
3
|
"""
|
4
4
|
|
5
|
+
from typing import Any, NoReturn
|
6
|
+
|
5
7
|
from value_object_pattern.decorators import validation
|
6
8
|
from value_object_pattern.models import ValueObject
|
7
9
|
|
@@ -33,4 +35,16 @@ class BytesValueObject(ValueObject[bytes]):
|
|
33
35
|
TypeError: If the `value` is not bytes.
|
34
36
|
"""
|
35
37
|
if type(value) is not bytes:
|
36
|
-
|
38
|
+
self._raise_value_is_not_bytes(value=value)
|
39
|
+
|
40
|
+
def _raise_value_is_not_bytes(self, value: Any) -> NoReturn:
|
41
|
+
"""
|
42
|
+
Raises a TypeError if the value object `value` is not bytes.
|
43
|
+
|
44
|
+
Args:
|
45
|
+
value (Any): The provided value.
|
46
|
+
|
47
|
+
Raises:
|
48
|
+
TypeError: If the `value` is not bytes.
|
49
|
+
"""
|
50
|
+
raise TypeError(f'BytesValueObject value <<<{str(object=value)}>>> must be bytes. Got <<<{type(value).__name__}>>> type.') # noqa: E501 # fmt: skip
|
@@ -2,6 +2,8 @@
|
|
2
2
|
FloatValueObject value object.
|
3
3
|
"""
|
4
4
|
|
5
|
+
from typing import Any, NoReturn
|
6
|
+
|
5
7
|
from value_object_pattern.decorators import validation
|
6
8
|
from value_object_pattern.models import ValueObject
|
7
9
|
|
@@ -33,4 +35,16 @@ class FloatValueObject(ValueObject[float]):
|
|
33
35
|
TypeError: If the `value` is not a float.
|
34
36
|
"""
|
35
37
|
if type(value) is not float:
|
36
|
-
|
38
|
+
self._raise_value_is_not_float(value=value)
|
39
|
+
|
40
|
+
def _raise_value_is_not_float(self, value: Any) -> NoReturn:
|
41
|
+
"""
|
42
|
+
Raises a TypeError if the value object `value` is not a float.
|
43
|
+
|
44
|
+
Args:
|
45
|
+
value (Any): The provided value.
|
46
|
+
|
47
|
+
Raises:
|
48
|
+
TypeError: If the `value` is not a float.
|
49
|
+
"""
|
50
|
+
raise TypeError(f'FloatValueObject value <<<{value}>>> must be a float. Got <<<{type(value).__name__}>>> type.') # noqa: E501 # fmt: skip
|
@@ -2,6 +2,8 @@
|
|
2
2
|
NegativeFloatValueObject value object.
|
3
3
|
"""
|
4
4
|
|
5
|
+
from typing import NoReturn
|
6
|
+
|
5
7
|
from value_object_pattern.decorators import validation
|
6
8
|
|
7
9
|
from .float_value_object import FloatValueObject
|
@@ -34,4 +36,16 @@ class NegativeFloatValueObject(FloatValueObject):
|
|
34
36
|
ValueError: If the `value` is not a negative float.
|
35
37
|
"""
|
36
38
|
if value >= 0:
|
37
|
-
|
39
|
+
self._raise_value_is_not_negative_float(value=value)
|
40
|
+
|
41
|
+
def _raise_value_is_not_negative_float(self, value: float) -> NoReturn:
|
42
|
+
"""
|
43
|
+
Raises a ValueError if the value object `value` is not a negative float.
|
44
|
+
|
45
|
+
Args:
|
46
|
+
value (float): The provided value.
|
47
|
+
|
48
|
+
Raises:
|
49
|
+
ValueError: If the `value` is not a negative float.
|
50
|
+
"""
|
51
|
+
raise ValueError(f'NegativeFloatValueObject value <<<{value}>>> must be a negative float.')
|
@@ -2,6 +2,8 @@
|
|
2
2
|
PositiveFloatValueObject value object.
|
3
3
|
"""
|
4
4
|
|
5
|
+
from typing import NoReturn
|
6
|
+
|
5
7
|
from value_object_pattern.decorators import validation
|
6
8
|
|
7
9
|
from .float_value_object import FloatValueObject
|
@@ -34,4 +36,16 @@ class PositiveFloatValueObject(FloatValueObject):
|
|
34
36
|
ValueError: If the `value` is not a positive float.
|
35
37
|
"""
|
36
38
|
if value <= 0:
|
37
|
-
|
39
|
+
self._raise_value_is_not_positive_float(value=value)
|
40
|
+
|
41
|
+
def _raise_value_is_not_positive_float(self, value: float) -> NoReturn:
|
42
|
+
"""
|
43
|
+
Raises a ValueError if the value object `value` is not a positive float.
|
44
|
+
|
45
|
+
Args:
|
46
|
+
value (float): The provided value.
|
47
|
+
|
48
|
+
Raises:
|
49
|
+
ValueError: If the `value` is not a positive float.
|
50
|
+
"""
|
51
|
+
raise ValueError(f'PositiveFloatValueObject value <<<{value}>>> must be a positive float.')
|
@@ -2,6 +2,8 @@
|
|
2
2
|
EvenIntegerValueObject value object.
|
3
3
|
"""
|
4
4
|
|
5
|
+
from typing import NoReturn
|
6
|
+
|
5
7
|
from value_object_pattern.decorators import validation
|
6
8
|
|
7
9
|
from .integer_value_object import IntegerValueObject
|
@@ -34,4 +36,16 @@ class EvenIntegerValueObject(IntegerValueObject):
|
|
34
36
|
ValueError: If the `value` is not an even number.
|
35
37
|
"""
|
36
38
|
if value % 2 != 0:
|
37
|
-
|
39
|
+
self._raise_value_is_not_even_number(value=value)
|
40
|
+
|
41
|
+
def _raise_value_is_not_even_number(self, value: int) -> NoReturn:
|
42
|
+
"""
|
43
|
+
Raises a ValueError if the value object `value` is not an even number.
|
44
|
+
|
45
|
+
Args:
|
46
|
+
value (int): The provided value.
|
47
|
+
|
48
|
+
Raises:
|
49
|
+
ValueError: If the `value` is not an even number.
|
50
|
+
"""
|
51
|
+
raise ValueError(f'EvenIntegerValueObject value <<<{value}>>> must be an even number.')
|
@@ -2,6 +2,8 @@
|
|
2
2
|
IntegerValueObject value object.
|
3
3
|
"""
|
4
4
|
|
5
|
+
from typing import Any, NoReturn
|
6
|
+
|
5
7
|
from value_object_pattern.decorators import validation
|
6
8
|
from value_object_pattern.models import ValueObject
|
7
9
|
|
@@ -33,4 +35,16 @@ class IntegerValueObject(ValueObject[int]):
|
|
33
35
|
TypeError: If the `value` is not an integer.
|
34
36
|
"""
|
35
37
|
if type(value) is not int:
|
36
|
-
|
38
|
+
self._raise_value_is_not_integer(value=value)
|
39
|
+
|
40
|
+
def _raise_value_is_not_integer(self, value: Any) -> NoReturn:
|
41
|
+
"""
|
42
|
+
Raises a TypeError if the value object `value` is not an integer.
|
43
|
+
|
44
|
+
Args:
|
45
|
+
value (Any): The provided value.
|
46
|
+
|
47
|
+
Raises:
|
48
|
+
TypeError: If the `value` is not an integer.
|
49
|
+
"""
|
50
|
+
raise TypeError(f'IntegerValueObject value <<<{value}>>> must be an integer. Got <<<{type(value).__name__}>>> type.') # noqa: E501 # fmt: skip
|
@@ -2,6 +2,8 @@
|
|
2
2
|
NegativeIntegerValueObject value object.
|
3
3
|
"""
|
4
4
|
|
5
|
+
from typing import NoReturn
|
6
|
+
|
5
7
|
from value_object_pattern.decorators import validation
|
6
8
|
|
7
9
|
from .integer_value_object import IntegerValueObject
|
@@ -34,4 +36,16 @@ class NegativeIntegerValueObject(IntegerValueObject):
|
|
34
36
|
ValueError: If the `value` is not a negative integer.
|
35
37
|
"""
|
36
38
|
if value >= 0:
|
37
|
-
|
39
|
+
self._raise_value_is_not_negative_integer(value=value)
|
40
|
+
|
41
|
+
def _raise_value_is_not_negative_integer(self, value: int) -> NoReturn:
|
42
|
+
"""
|
43
|
+
Raises a ValueError if the value object `value` is not a negative integer.
|
44
|
+
|
45
|
+
Args:
|
46
|
+
value (int): The provided value.
|
47
|
+
|
48
|
+
Raises:
|
49
|
+
ValueError: If the `value` is not a negative integer.
|
50
|
+
"""
|
51
|
+
raise ValueError(f'NegativeIntegerValueObject value <<<{value}>>> must be a negative integer.')
|
@@ -2,6 +2,8 @@
|
|
2
2
|
OddIntegerValueObject value object.
|
3
3
|
"""
|
4
4
|
|
5
|
+
from typing import NoReturn
|
6
|
+
|
5
7
|
from value_object_pattern.decorators import validation
|
6
8
|
|
7
9
|
from .integer_value_object import IntegerValueObject
|
@@ -34,4 +36,16 @@ class OddIntegerValueObject(IntegerValueObject):
|
|
34
36
|
ValueError: If the `value` is not an odd number.
|
35
37
|
"""
|
36
38
|
if value % 2 == 0:
|
37
|
-
|
39
|
+
self._raise_value_is_not_odd_number(value=value)
|
40
|
+
|
41
|
+
def _raise_value_is_not_odd_number(self, value: int) -> NoReturn:
|
42
|
+
"""
|
43
|
+
Raises a ValueError if the value object `value` is not an odd number.
|
44
|
+
|
45
|
+
Args:
|
46
|
+
value (int): The provided value.
|
47
|
+
|
48
|
+
Raises:
|
49
|
+
ValueError: If the `value` is not an odd number.
|
50
|
+
"""
|
51
|
+
raise ValueError(f'OddIntegerValueObject value <<<{value}>>> must be an odd number.')
|
@@ -2,6 +2,8 @@
|
|
2
2
|
PositiveIntegerValueObject value object.
|
3
3
|
"""
|
4
4
|
|
5
|
+
from typing import NoReturn
|
6
|
+
|
5
7
|
from value_object_pattern.decorators import validation
|
6
8
|
|
7
9
|
from .integer_value_object import IntegerValueObject
|
@@ -34,4 +36,16 @@ class PositiveIntegerValueObject(IntegerValueObject):
|
|
34
36
|
ValueError: If the `value` is not a positive integer.
|
35
37
|
"""
|
36
38
|
if value <= 0:
|
37
|
-
|
39
|
+
self._raise_value_is_not_positive_integer(value=value)
|
40
|
+
|
41
|
+
def _raise_value_is_not_positive_integer(self, value: int) -> NoReturn:
|
42
|
+
"""
|
43
|
+
Raises a ValueError if the value object `value` is not a positive integer.
|
44
|
+
|
45
|
+
Args:
|
46
|
+
value (int): The provided value.
|
47
|
+
|
48
|
+
Raises:
|
49
|
+
ValueError: If the `value` is not a positive integer.
|
50
|
+
"""
|
51
|
+
raise ValueError(f'PositiveIntegerValueObject value <<<{value}>>> must be a positive integer.')
|