Class: Lutaml::UmlRepository::StaticSite::IDGenerator

Inherits:
Object
  • Object
show all
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.

Examples:

generator = IDGenerator.new
pkg_id = generator.package_id(package)  # => "pkg_a1b2c3d4"
cls_id = generator.class_id(klass)      # => "cls_e5f6g7h8"

Instance Method Summary collapse

Constructor Details

#initializeIDGenerator

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

Parameters:

Returns:

  • (String)

    Stable association ID (e.g., “assoc_a1b2c3d4”)



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

Parameters:

  • attribute (Object)

    Attribute object

  • owner (Object)

    Owner class

Returns:

  • (String)

    Stable attribute ID (e.g., “attr_a1b2c3d4”)



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

Parameters:

Returns:

  • (String)

    Stable class ID (e.g., “cls_a1b2c3d4”)



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_cachevoid

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

Parameters:

  • diagram (Object)

    Diagram object

Returns:

  • (String)

    Stable diagram ID (e.g., “diag_a1b2c3d4”)



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

Parameters:

  • type (String)

    Document type (class, attribute, etc.)

  • entity_id (String)

    Entity XMI ID

Returns:

  • (String)

    Stable document ID (e.g., “doc_class_a1b2c3d4”)



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

Parameters:

  • operation (Object)

    Operation object

  • owner (Object)

    Owner class

Returns:

  • (String)

    Stable operation ID (e.g., “op_a1b2c3d4”)



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

Parameters:

Returns:

  • (String)

    Stable package ID (e.g., “pkg_a1b2c3d4”)



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