Class: Ea::Mdg::Document

Inherits:
Object
  • Object
show all
Defined in:
lib/ea/mdg/document.rb

Overview

One MDG technology file's parsed model. Immutable container carrying the technology's name, packages, classifiers, stereotype definitions, and generalization relationships.

Two MDG file formats are supported:

1. XMI format (UML:Model/UML:Class/...) — carries reference
 model classes with properties and generalizations.
2. MDG.Technology format (<MDG.Technology>/<UMLProfiles>) —
 carries stereotype definitions with tagged-value specs.

Both formats contribute to the same Document; stereotypes and classifiers coexist without coupling.

Lookups are O(1) via lazily-built hash indexes. Callers do not mutate the Document.

Defined Under Namespace

Classes: ClassifierEntry, GeneralizationEntry, PropertyEntry, StereotypeEntry, TaggedValueSpec

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(technology_name:, classifiers:, generalizations:, packages:, stereotypes: []) ⇒ Document

Returns a new instance of Document.



47
48
49
50
51
52
53
54
# File 'lib/ea/mdg/document.rb', line 47

def initialize(technology_name:, classifiers:, generalizations:,
               packages:, stereotypes: [])
  @technology_name = technology_name
  @classifiers = classifiers.freeze
  @generalizations = generalizations.freeze
  @packages = packages.freeze
  @stereotypes = stereotypes.freeze
end

Instance Attribute Details

#classifiersObject (readonly)

Returns the value of attribute classifiers.



44
45
46
# File 'lib/ea/mdg/document.rb', line 44

def classifiers
  @classifiers
end

#generalizationsObject (readonly)

Returns the value of attribute generalizations.



44
45
46
# File 'lib/ea/mdg/document.rb', line 44

def generalizations
  @generalizations
end

#packagesObject (readonly)

Returns the value of attribute packages.



44
45
46
# File 'lib/ea/mdg/document.rb', line 44

def packages
  @packages
end

#stereotypesObject (readonly)

Returns the value of attribute stereotypes.



44
45
46
# File 'lib/ea/mdg/document.rb', line 44

def stereotypes
  @stereotypes
end

#technology_nameObject (readonly)

Returns the value of attribute technology_name.



44
45
46
# File 'lib/ea/mdg/document.rb', line 44

def technology_name
  @technology_name
end

Instance Method Details

#ancestors_of(classifier_id) ⇒ Object

Enumerates each classifier's ancestor chain (parent, grandparent, ...). Stops at the root or when a cycle is detected.



80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/ea/mdg/document.rb', line 80

def ancestors_of(classifier_id)
  seen = {}
  Enumerator.new do |yielder|
    current_id = classifier_id
    while current_id && !seen.key?(current_id)
      seen[current_id] = true
      parent = parent_of(current_id)
      break unless parent

      yielder << parent
      current_id = parent.id
    end
  end
end

#find_by_guid(guid) ⇒ Object

O(1) classifier lookup by EA GUID. Returns ClassifierEntry or nil.



58
59
60
# File 'lib/ea/mdg/document.rb', line 58

def find_by_guid(guid)
  classifier_guid_index[guid]
end

#find_by_name(name) ⇒ Object

O(1) classifier lookup by name. Returns the FIRST match — MDGs typically use unique class names within a technology.



64
65
66
# File 'lib/ea/mdg/document.rb', line 64

def find_by_name(name)
  classifier_name_index[name]
end

#find_stereotype(name) ⇒ Object

O(1) stereotype lookup by name. Returns StereotypeEntry or nil.



96
97
98
# File 'lib/ea/mdg/document.rb', line 96

def find_stereotype(name)
  stereotype_index[name]
end

#parent_of(classifier_id) ⇒ Object

Returns the parent ClassifierEntry for a given child id, or nil when the child has no MDG-defined parent.



70
71
72
73
74
75
# File 'lib/ea/mdg/document.rb', line 70

def parent_of(classifier_id)
  gen = generalizations.find { |g| g.specific_id == classifier_id }
  return nil unless gen

  find_by_guid(gen.general_id)
end