From 2c99e78cc9e54598db6ea242ba6996778e783799 Mon Sep 17 00:00:00 2001 From: "Alexie (Boyong) Madolid" Date: Fri, 6 Sep 2024 01:33:53 +0800 Subject: [PATCH] [MINOR]: Override get_object/object_ref to use ref_id --- jaclang_jaseci/plugin/jaseci.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/jaclang_jaseci/plugin/jaseci.py b/jaclang_jaseci/plugin/jaseci.py index 654c6ed..f05ae34 100644 --- a/jaclang_jaseci/plugin/jaseci.py +++ b/jaclang_jaseci/plugin/jaseci.py @@ -1,6 +1,7 @@ """Jac Language Features.""" from collections import OrderedDict +from contextlib import suppress from dataclasses import Field, MISSING, fields from functools import wraps from os import getenv @@ -33,6 +34,7 @@ from ..core.architype import ( Anchor, Architype, + BaseAnchor, EdgeArchitype, GenericEdge, NodeAnchor, @@ -434,3 +436,19 @@ def builder(source: NodeAnchor, target: NodeAnchor) -> EdgeArchitype: return JacFeatureDefaults.build_edge( # type:ignore[return-value] is_undirected=is_undirected, conn_type=conn_type, conn_assign=conn_assign ) + + @staticmethod + @hookimpl + def get_object(id: str) -> Architype | None: + """Get object via reference id.""" + with suppress(ValueError): + if isinstance(architype := BaseAnchor.ref(id).architype, Architype): + return architype + + return None + + @staticmethod + @hookimpl + def object_ref(obj: Architype) -> str: + """Get object reference id.""" + return str(obj.__jac__.ref_id)