Class: Ea::Mdg::Document
- Inherits:
-
Object
- Object
- Ea::Mdg::Document
- 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
-
#classifiers ⇒ Object
readonly
Returns the value of attribute classifiers.
-
#generalizations ⇒ Object
readonly
Returns the value of attribute generalizations.
-
#packages ⇒ Object
readonly
Returns the value of attribute packages.
-
#stereotypes ⇒ Object
readonly
Returns the value of attribute stereotypes.
-
#technology_name ⇒ Object
readonly
Returns the value of attribute technology_name.
Instance Method Summary collapse
-
#ancestors_of(classifier_id) ⇒ Object
Enumerates each classifier's ancestor chain (parent, grandparent, ...).
-
#find_by_guid(guid) ⇒ Object
O(1) classifier lookup by EA GUID.
-
#find_by_name(name) ⇒ Object
O(1) classifier lookup by name.
-
#find_stereotype(name) ⇒ Object
O(1) stereotype lookup by name.
-
#initialize(technology_name:, classifiers:, generalizations:, packages:, stereotypes: []) ⇒ Document
constructor
A new instance of Document.
-
#parent_of(classifier_id) ⇒ Object
Returns the parent ClassifierEntry for a given child id, or nil when the child has no MDG-defined parent.
Constructor Details
#initialize(technology_name:, classifiers:, generalizations:, packages:, stereotypes: []) ⇒ Document
Returns a new instance of Document.
46 47 48 49 50 51 52 53 |
# File 'lib/ea/mdg/document.rb', line 46 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
#classifiers ⇒ Object (readonly)
Returns the value of attribute classifiers.
43 44 45 |
# File 'lib/ea/mdg/document.rb', line 43 def classifiers @classifiers end |
#generalizations ⇒ Object (readonly)
Returns the value of attribute generalizations.
43 44 45 |
# File 'lib/ea/mdg/document.rb', line 43 def generalizations @generalizations end |
#packages ⇒ Object (readonly)
Returns the value of attribute packages.
43 44 45 |
# File 'lib/ea/mdg/document.rb', line 43 def packages @packages end |
#stereotypes ⇒ Object (readonly)
Returns the value of attribute stereotypes.
43 44 45 |
# File 'lib/ea/mdg/document.rb', line 43 def stereotypes @stereotypes end |
#technology_name ⇒ Object (readonly)
Returns the value of attribute technology_name.
43 44 45 |
# File 'lib/ea/mdg/document.rb', line 43 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.
79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/ea/mdg/document.rb', line 79 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.
57 58 59 |
# File 'lib/ea/mdg/document.rb', line 57 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.
63 64 65 |
# File 'lib/ea/mdg/document.rb', line 63 def find_by_name(name) classifier_name_index[name] end |
#find_stereotype(name) ⇒ Object
O(1) stereotype lookup by name. Returns StereotypeEntry or nil.
95 96 97 |
# File 'lib/ea/mdg/document.rb', line 95 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.
69 70 71 72 73 74 |
# File 'lib/ea/mdg/document.rb', line 69 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 |