deirokay.backend.register_backend_method
- deirokay.backend.register_backend_method(alias_for: str, backend: Backend, *, force: bool = False) Union[Callable, Type][source]
Modify a method to make it an alternative (alias) for another method (alias_for) when the specified backend is active. Should be used as an decorator as in: @register_backend_method(‘method_name’, <Backend object>).
It could be handful to declare helper decorators using this one for common methods for a given resource. For instance, if a hierarchy of classes should implement a do_it method to work with different backend, we could implement a do_it decorator and use it to decorate backend-specific methods.
def do_it(backend): register_backend_method('do_it', backend) class MultiBackendClass(MultiBackendMixin): @do_it(Backend.TYPE1) def _do_it_1(...): ... @do_it(Backend.TYPE2) def _do_it_2(...): ...
- Parameters
alias_for (str) – The name of the method to be substituted with a backend-specific version.
backend (Backend) – The backend to use when running the method.
force (bool, optional) – Force overwrite target method when it already exists. Defaults to False.