def resource_method_info(self, method) -> tuple:
"""Return the (class) name of the resource and its type, which
is associated with the provided method (function).
Used by this class' decorators to determine the name of the
instance which subclassed this class, e.g., `WorksCollection`,
as well as passing a nice `enum` for determining if it's
a collection or singleton resource.
Arguments:
method (function): Hopefully a method which belongs
to an instance that inherited from this class.
Raises:
InvalidResourceName: If the function belongs to
a resource class whose name neither ends in
`Collection` nor `Singleton`.
Returns:
tuple[str, str]: Resource class name, resoure type.
"""
resource_class_name = self.__class__.__name__
if resource_class_name.endswith('Collection'):
resource_type = ResourceType.collection
elif resource_class_name.endswith('Singleton'):
resource_type = ResourceType.singleton
else:
raise InvalidResourceName(resource_class_name)
return resource_class_name, resource_type
评论列表
文章目录