Class: Lutaml::UmlRepository::StaticSite::IDGenerator
- Inherits:
-
Object
- Object
- Lutaml::UmlRepository::StaticSite::IDGenerator
- Defined in:
- lib/lutaml/uml_repository/static_site/id_generator.rb
Overview
Generates stable, short IDs for entities in the JSON data model.
Uses MD5 hash of XMI IDs to create consistent, collision-resistant IDs that remain stable across multiple generations.
Instance Method Summary collapse
-
#association_id(association) ⇒ String
Generate ID for an association.
-
#attribute_id(attribute, owner) ⇒ String
Generate ID for an attribute.
-
#class_id(klass) ⇒ String
Generate ID for a class.
-
#clear_cache ⇒ void
Clear the cache (useful for testing).
-
#diagram_id(diagram) ⇒ String
Generate ID for a diagram.
-
#document_id(type, entity_id) ⇒ String
Generate ID for a search document.
-
#initialize ⇒ IDGenerator
constructor
A new instance of IDGenerator.
-
#operation_id(operation, owner) ⇒ String
Generate ID for an operation.
-
#package_id(package) ⇒ String
Generate ID for a package.
Constructor Details
#initialize ⇒ IDGenerator
Returns a new instance of IDGenerator.
18 19 20 |
# File 'lib/lutaml/uml_repository/static_site/id_generator.rb', line 18 def initialize @cache = {} end |
Instance Method Details
#association_id(association) ⇒ String
Generate ID for an association
58 59 60 61 |
# File 'lib/lutaml/uml_repository/static_site/id_generator.rb', line 58 def association_id(association) cache_key = [:association, association.xmi_id] @cache[cache_key] ||= generate_id("assoc", association.xmi_id) end |
#attribute_id(attribute, owner) ⇒ String
Generate ID for an attribute
47 48 49 50 51 52 |
# File 'lib/lutaml/uml_repository/static_site/id_generator.rb', line 47 def attribute_id(attribute, owner) # Use combination of owner ID and attribute name for uniqueness composite_key = "#{owner.xmi_id}::#{attribute.name}" cache_key = [:attribute, composite_key] @cache[cache_key] ||= generate_id("attr", composite_key) end |
#class_id(klass) ⇒ String
Generate ID for a class
37 38 39 40 |
# File 'lib/lutaml/uml_repository/static_site/id_generator.rb', line 37 def class_id(klass) cache_key = [:class, klass.xmi_id] @cache[cache_key] ||= generate_id("cls", klass.xmi_id) end |
#clear_cache ⇒ void
This method returns an undefined value.
Clear the cache (useful for testing)
96 97 98 |
# File 'lib/lutaml/uml_repository/static_site/id_generator.rb', line 96 def clear_cache @cache.clear end |
#diagram_id(diagram) ⇒ String
Generate ID for a diagram
78 79 80 81 |
# File 'lib/lutaml/uml_repository/static_site/id_generator.rb', line 78 def diagram_id(diagram) cache_key = [:diagram, diagram.xmi_id] @cache[cache_key] ||= generate_id("diag", diagram.xmi_id) end |
#document_id(type, entity_id) ⇒ String
Generate ID for a search document
88 89 90 91 |
# File 'lib/lutaml/uml_repository/static_site/id_generator.rb', line 88 def document_id(type, entity_id) cache_key = [:document, type, entity_id] @cache[cache_key] ||= generate_id("doc_#{type}", entity_id) end |
#operation_id(operation, owner) ⇒ String
Generate ID for an operation
68 69 70 71 72 |
# File 'lib/lutaml/uml_repository/static_site/id_generator.rb', line 68 def operation_id(operation, owner) composite_key = "#{owner.xmi_id}::#{operation.name}" cache_key = [:operation, composite_key] @cache[cache_key] ||= generate_id("op", composite_key) end |
#package_id(package) ⇒ String
Generate ID for a package
26 27 28 29 30 31 |
# File 'lib/lutaml/uml_repository/static_site/id_generator.rb', line 26 def package_id(package) # Use XMI ID for uniqueness - each package has unique XMI ID # even if names are identical in different hierarchies cache_key = [:package, package.xmi_id] @cache[cache_key] ||= generate_id("pkg", package.xmi_id) end |