Class: Ea::Mdg::Registry

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/ea/mdg/registry.rb

Overview

Multi-MDG lookup. Holds one or more loaded MDG Documents and exposes a unified lookup surface (by name or by GUID) that searches across all registered technologies.

Source adapters OPTIONALLY accept an Mdg::Registry and use it to resolve inherited attributes from MDG-defined parent classes when a local Classifier's generalization parent isn't in the local model.

Example:

registry = Ea::Mdg::Registry.new
registry.register(Ea::Mdg::Loader.from_path("MDG_ISO19103.xml"))
registry.find_classifier_by_name("Any")         # → ClassifierEntry
registry.inherited_properties_for("EAID_...")   # → [PropertyEntry, ...]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRegistry

Returns a new instance of Registry.



25
26
27
# File 'lib/ea/mdg/registry.rb', line 25

def initialize
  @documents = []
end

Instance Attribute Details

#documentsObject (readonly)

Returns the value of attribute documents.



23
24
25
# File 'lib/ea/mdg/registry.rb', line 23

def documents
  @documents
end

Instance Method Details

#each(&block) ⇒ Object



36
37
38
# File 'lib/ea/mdg/registry.rb', line 36

def each(&block)
  @documents.each(&block)
end

#find_classifier_by_guid(guid) ⇒ Object

Lookup by GUID across all registered technologies.



49
50
51
52
53
54
55
# File 'lib/ea/mdg/registry.rb', line 49

def find_classifier_by_guid(guid)
  each do |doc|
    found = doc.find_by_guid(guid)
    return found if found
  end
  nil
end

#find_classifier_by_name(name) ⇒ Object

Lookup by name across all registered technologies. Returns the first match (technologies are searched in registration order).



60
61
62
63
64
65
66
# File 'lib/ea/mdg/registry.rb', line 60

def find_classifier_by_name(name)
  each do |doc|
    found = doc.find_by_name(name)
    return found if found
  end
  nil
end

#inherited_properties_for(classifier_guid) ⇒ Object

Returns all Properties inherited from MDG ancestors of the given classifier. The classifier's OWN properties are excluded — only inherited MDG attributes are returned.

Caller passes the local Classifier's EA GUID. The local Classifier is looked up across all registered MDGs; if found, its MDG ancestor chain is walked and each ancestor's properties are collected in order.



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/ea/mdg/registry.rb', line 76

def inherited_properties_for(classifier_guid)
  result = []
  seen_property_names = {}

  each do |doc|
    classifier = doc.find_by_guid(classifier_guid)
    next unless classifier

    doc.ancestors_of(classifier_guid).each do |ancestor|
      (ancestor.properties || []).each do |prop|
        next if seen_property_names.key?(prop.name)

        seen_property_names[prop.name] = true
        result << prop
      end
    end
  end

  result
end

#register(document) ⇒ Object

Register an MDG Document. Subsequent registrations of the same technology_name replace the prior one (last-wins).



31
32
33
34
# File 'lib/ea/mdg/registry.rb', line 31

def register(document)
  @documents.reject! { |d| d.technology_name == document.technology_name }
  @documents << document
end

#sizeObject



40
41
42
# File 'lib/ea/mdg/registry.rb', line 40

def size
  @documents.size
end

#technology_namesObject



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

def technology_names
  @documents.map(&:technology_name)
end