3131
3232class BomRefDiscriminator :
3333 """
34- Utility to give BomRefs unique values.
34+ Ensure that a collection of BomRef objects has unique, non‑empty values.
35+
36+ The discriminator inspects the provided BomRef instances and assigns new,
37+ automatically generated identifiers to any BomRef whose value is missing
38+ or duplicates another. Original values are preserved so they can be
39+ restored later via `reset()` or by using this class as a context manager.
3540 """
3641
3742 def __init__ (self , bomrefs : Iterable ['BomRef' ], prefix : str = 'BomRef' ) -> None :
@@ -47,8 +52,10 @@ def __exit__(self, exc_type: Any, exc_val: Any, exc_tb: Any) -> None:
4752
4853 def discriminate (self ) -> None :
4954 """
50- Check BomRefs' values for uniqueness.
51- Duplications will be assigned a unique value.
55+ Enforce uniqueness across all BomRef values.
56+
57+ Any BomRef whose value is `None` or duplicates a previously encountered
58+ value is assigned a newly generated unique identifier.
5259 """
5360 known_values = []
5461 for bomref , _ in self ._bomrefs :
@@ -60,7 +67,7 @@ def discriminate(self) -> None:
6067
6168 def reset (self ) -> None :
6269 """
63- Set BomRefs' values to the initial state.
70+ Restore all BomRef values to their original state.
6471 """
6572 for bomref , original_value in self ._bomrefs :
6673 bomref .value = original_value
@@ -70,6 +77,14 @@ def _make_unique(self) -> str:
7077
7178 @classmethod
7279 def from_bom (cls , bom : 'Bom' , prefix : str = 'BomRef' ) -> 'BomRefDiscriminator' :
80+ """
81+ Create a discriminator for all BomRefs contained within a BOM.
82+
83+ This includes BomRefs from
84+ - components
85+ - services
86+ - vulnerabilities
87+ """
7388 return cls (chain (
7489 map (lambda c : c .bom_ref , bom ._get_all_components ()),
7590 map (lambda s : s .bom_ref , bom .services ),
0 commit comments