def model(
service_name: str,
fixture_name: str | None = None,
db_query_docs_limit: int = 1000,
is_create_doc: bool = True,
is_update_doc: bool = True,
is_delete_doc: bool = True,
) -> Any:
"""Decorator for converting Python Classe into Ramifice Model."""
try:
if not isinstance(service_name, str):
msg = "Parameter `service_name` - Must be `str` type!"
raise AssertionError(msg)
if not isinstance(fixture_name, (str, type(None))):
msg = "Parameter `fixture_name` - Must be `str | None` type!"
raise AssertionError(msg)
if not isinstance(db_query_docs_limit, int):
msg = "Parameter `db_query_docs_limit` - Must be `int` type!"
raise AssertionError(msg)
if not isinstance(is_create_doc, bool):
msg = "Parameter `is_create_doc` - Must be `bool` type!"
raise AssertionError(msg)
if not isinstance(is_update_doc, bool):
msg = "Parameter `is_update_doc` - Must be `bool` type!"
raise AssertionError(msg)
if not isinstance(is_delete_doc, bool):
msg = "Parameter `is_delete_doc` - Must be `bool` type!"
raise AssertionError(msg)
except AssertionError as err:
logger.critical(str(err))
raise err
def decorator(cls: Any) -> Any:
if REGEX["service_name"].match(service_name) is None:
regex_str: str = "^[A-Z][a-zA-Z0-9]{0,24}$"
msg = f"Does not match the regular expression: {regex_str}"
logger.critical(msg)
raise DoesNotMatchRegexError(regex_str)
if fixture_name is not None:
fixture_path = f"config/fixtures/{fixture_name}.yml"
if not Path(fixture_path).exists():
msg = (
f"Model: `{cls.__module__}.{cls.__name__}` > "
+ "META param: `fixture_name` => "
+ f"Fixture the `{fixture_path}` not exists!"
)
logger.critical(msg)
raise PanicError(msg)
attrs = dict(cls.__dict__)
attrs["__dict__"] = Model.__dict__["__dict__"]
metadata = {
"service_name": service_name,
"fixture_name": fixture_name,
"db_query_docs_limit": db_query_docs_limit,
"is_create_doc": is_create_doc,
"is_update_doc": is_update_doc,
"is_delete_doc": is_delete_doc,
}
attrs["META"] = {
**metadata,
**caching(cls, service_name),
}
return type(
cls.__name__,
(
Model,
QPaladinsMixin,
QCommonsMixin,
),
attrs,
)
return decorator