Skip to content

service

dandy.intel.service

IntelService

Bases: BaseService['IntelServiceMixin']

Source code in dandy/core/service/service.py
def __init__(self, obj: Any = None):
    if self.has_obj_service_instance(obj):
        return

    self._obj_type_name: str = str(
        list(self.__class__.__annotations__.values())[0]
    ).split('.')[-1]

    if obj is None:
        return

    self._obj_mro_type_names = [cls.__name__ for cls in obj.__class__.__mro__]

    if not self._obj_type_name in self._obj_mro_type_names:
        message = f'{self.__class__.__name__} was instantiated with obj type "{obj.__class__.__name__}" and failed as it was expecting "{self._obj_type_name}".'
        raise ServiceCriticalException(message)

    self._obj_type: type[TypeAny] = obj.__class__

    if self._obj_type is None or self._obj_type is ...:
        message = f'{self.__class__.__name__} top class attribute must have an annotated type.'
        raise ServiceCriticalException(message)

    self.obj: TypeAny = obj

    if ABC not in self.__class__.__bases__:
        if not self._obj_is_valid:
            message = f'{self._obj_type_name} failed to validate on {self.__class__.__name__}'
            raise ServiceCriticalException(message)

    self.__post_init__()

    if not hasattr(obj, self.generate_service_instance_name(self.__class__)):
        message = f'To use "{self.__class__.__name__}" can only be attached to an object with a "{self.generate_service_instance_name(self.__class__)}" attribute.'
        raise ServiceCriticalException(message)

    self.set_obj_service_instance(obj, self)

obj instance-attribute

intel_class_from_callable_signature staticmethod

Source code in dandy/intel/service.py
@staticmethod
def intel_class_from_callable_signature(
        callable_: Callable,
) -> Type[BaseIntel]:
    return IntelClassGenerator.from_callable_signature(callable_)

intel_class_from_simple_json_schema staticmethod

Source code in dandy/intel/service.py
@staticmethod
def intel_class_from_simple_json_schema(
        simple_json_schema: dict | str
) -> type[BaseIntel]:
    return IntelClassGenerator.from_simple_json_schema(simple_json_schema)

json_str_to_intel_object staticmethod

Source code in dandy/intel/service.py
@staticmethod
def json_str_to_intel_object(
        json_str: str,
        intel: BaseIntel | type[BaseIntel],
) -> BaseIntel:
    return IntelFactory.json_str_to_intel_object(
            json_str=json_str,
            intel=intel
        )