Changeset df459f7 in flexoentity
- Timestamp:
- 11/29/25 14:55:33 (7 weeks ago)
- Branches:
- master
- Children:
- 918474d
- Parents:
- 4a79b76
- Files:
-
- 2 added
- 3 edited
-
flexoentity/__init__.py (modified) (2 diffs)
-
flexoentity/domain_manager.py (added)
-
flexoentity/flexo_collection.py (modified) (9 diffs)
-
tests/conftest.py (modified) (2 diffs)
-
tests/test_domain.py (added)
Legend:
- Unmodified
- Added
- Removed
-
flexoentity/__init__.py
r4a79b76 rdf459f7 15 15 from .flexo_collection import FlexoCollection 16 16 from .domain import Domain 17 from .domain_manager import DomainManager, DuplicateDomainError 17 18 from .flexo_signature import FlexoSignature, CertificateReference 18 19 from .signing_backends import get_signing_backend … … 24 25 "EntityType", 25 26 "Domain", 27 "DomainManager", 28 "DuplicateDomainError", 26 29 "EntityState", 27 30 "FlexoCollection", -
flexoentity/flexo_collection.py
r4a79b76 rdf459f7 5 5 A minimal collection for FlexOEntities. 6 6 7 - No domain rules 8 - No uniqueness validation (last write wins) 9 - No state or lifecycle logic 10 - No typing constraints 11 12 The goal is to provide a Smalltalk-like Collection object with a simple 13 protocol for storing, retrieving, iterating, and serializing FlexOEntities. 7 - Default key = entity.flexo_id 8 - Optional override key=... for special cases (e.g., domains) 9 - Smalltalk-like protocol preserved 10 - Dict-based: fast lookup 11 - Backwards compatible API 14 12 """ 15 16 13 17 14 from .flexo_entity import FlexoEntity … … 21 18 class FlexoCollection: 22 19 """ 23 A minimal collection of FlexOEntities, keyed by FlexOID .20 A minimal collection of FlexOEntities, keyed by FlexOID by default. 24 21 25 22 Examples: 26 23 coll = FlexoCollection() 27 coll.add(entity) 28 entity = coll.get(some_id) 24 coll.add(entity) # uses entity.flexo_id as key 25 coll.add(domain, key=domain.domain_id) # override key if needed 26 ent = coll.get(some_id) 29 27 for e in coll: 30 28 ... … … 32 30 33 31 def __init__(self, items=None): 32 # internal dict-based storage 34 33 self._items = {} 35 34 … … 38 37 self.add(it) 39 38 40 def add(self, entity: FlexoEntity): 41 """Add or replace an entity by its FlexOID. Overwrites on duplicate IDs.""" 42 self._items[entity.flexo_id] = entity 39 # ------------------------------------------------------------------ 40 # Core API (unchanged externally, enhanced internally) 41 # ------------------------------------------------------------------ 42 43 def add(self, entity: FlexoEntity, key=None): 44 """ 45 Add or replace an entity. 46 47 - If key is None → use entity.flexo_id 48 - If key is given → use caller-provided key 49 """ 50 if key is None: 51 try: 52 key = entity.flexo_id 53 except AttributeError: 54 raise TypeError( 55 "Items must have .flexo_id or explicitly use add(entity, key=...)." 56 ) 57 58 self._items[key] = entity # overwrite is intentional & preserved 43 59 44 60 def remove(self, oid: FlexOID): 45 """Remove an entity by ID, ignoring if missing ."""61 """Remove an entity by ID, ignoring if missing (API preserved).""" 46 62 self._items.pop(oid, None) 63 64 def clear(self): 65 self._items = {} 47 66 48 67 def get(self, oid: FlexOID): … … 60 79 return iter(self._items.values()) 61 80 81 # ------------------------------------------------------------------ 82 # Additional public helpers (unchanged) 83 # ------------------------------------------------------------------ 84 62 85 def entities(self): 63 """Return all entities ."""86 """Return all entities as a list.""" 64 87 return list(self._items.values()) 65 88 66 89 def ids(self): 67 """Return all IDs."""90 """Return all stored keys.""" 68 91 return list(self._items.keys()) 69 92 70 93 # ------------------------------------------------------------------ 71 # Smalltalk-inspired interface 94 # Smalltalk-inspired interface (unchanged) 72 95 # ------------------------------------------------------------------ 73 96 … … 77 100 78 101 def at_put(self, oid, entity): 79 """Smalltalk-style setter ."""102 """Smalltalk-style setter (kept).""" 80 103 self._items[oid] = entity 81 104 … … 90 113 91 114 # ------------------------------------------------------------------ 92 # Serialization helpers 115 # Serialization helpers (unchanged) 93 116 # ------------------------------------------------------------------ 94 117 95 118 def to_dict_list(self): 96 """Serialize entities to alist of dicts."""119 """Serialize all entities to list of dicts.""" 97 120 return [e.to_dict() for e in self._items.values()] 98 121 … … 102 125 Deserialize a list of dicts into a FlexoCollection. 103 126 104 Uses FlexoEntity.from_dict to dispatch to the correct subclass.127 Uses FlexoEntity.from_dict() to dispatch to the correct subclass. 105 128 """ 106 129 c = cls() … … 110 133 return c 111 134 135 # ------------------------------------------------------------------ 136 112 137 def __repr__(self) -> str: 113 138 return f"<FlexoCollection size={len(self._items)}>" -
tests/conftest.py
r4a79b76 rdf459f7 3 3 from pathlib import Path 4 4 from datetime import datetime 5 from flexoentity import Domain, FlexoSignature 5 from flexoentity import Domain, FlexoSignature, DomainManager 6 6 from flexoentity import get_signing_backend, CertificateReference 7 7 … … 28 28 29 29 30 @pytest.fixture 31 def sample_domain_manager(): 32 return DomainManager() 33 30 34 # ───────────────────────────────────────────────────────────── 31 35 # Basic test data directory + PEM test files 32 36 # ───────────────────────────────────────────────────────────── 37 33 38 34 39 @pytest.fixture(scope="session")
Note:
See TracChangeset
for help on using the changeset viewer.
