Class: Ea::Mdg::Registry
- Inherits:
-
Object
- Object
- Ea::Mdg::Registry
- 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
-
#documents ⇒ Object
readonly
Returns the value of attribute documents.
Class Method Summary collapse
- .expand_mdg_path(path) ⇒ Object
-
.from_paths(paths) ⇒ Ea::Mdg::Registry
Build a registry from MDG XML files and/or directories (directories are globbed recursively).
Instance Method Summary collapse
- #each(&block) ⇒ Object
-
#find_classifier_by_guid(guid) ⇒ Object
Lookup by GUID across all registered technologies.
-
#find_classifier_by_name(name) ⇒ Object
Lookup by name across all registered technologies.
-
#inherited_properties_for(classifier_guid) ⇒ Object
Returns all Properties inherited from MDG ancestors of the given classifier.
-
#initialize ⇒ Registry
constructor
A new instance of Registry.
-
#register(document) ⇒ Object
Register an MDG Document.
- #size ⇒ Object
- #technology_names ⇒ Object
-
#unregister(technology_name) ⇒ Object
(also: #remove)
Remove an MDG Document by technology name.
Constructor Details
#initialize ⇒ Registry
Returns a new instance of Registry.
25 26 27 |
# File 'lib/ea/mdg/registry.rb', line 25 def initialize @documents = [] end |
Instance Attribute Details
#documents ⇒ Object (readonly)
Returns the value of attribute documents.
23 24 25 |
# File 'lib/ea/mdg/registry.rb', line 23 def documents @documents end |
Class Method Details
.expand_mdg_path(path) ⇒ Object
46 47 48 |
# File 'lib/ea/mdg/registry.rb', line 46 def self.(path) File.directory?(path) ? Dir.glob(File.join(path, "**/*.xml")).sort : [path] end |
.from_paths(paths) ⇒ Ea::Mdg::Registry
Build a registry from MDG XML files and/or directories (directories are globbed recursively). Unloadable files are skipped — MDG discovery is a boundary where partial input is normal (set EA_DEBUG=1 to see what was skipped).
36 37 38 39 40 41 42 43 44 |
# File 'lib/ea/mdg/registry.rb', line 36 def self.from_paths(paths) new.tap do |registry| paths.flat_map { |path| (path) }.each do |file| registry.register(Loader.from_path(file).document) rescue StandardError => e warn "Skipped MDG #{file}: #{e.}" if ENV["EA_DEBUG"] end end end |
Instance Method Details
#each(&block) ⇒ Object
74 75 76 |
# File 'lib/ea/mdg/registry.rb', line 74 def each(&block) @documents.each(&block) end |
#find_classifier_by_guid(guid) ⇒ Object
Lookup by GUID across all registered technologies.
87 88 89 90 91 92 93 |
# File 'lib/ea/mdg/registry.rb', line 87 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).
98 99 100 101 102 103 104 |
# File 'lib/ea/mdg/registry.rb', line 98 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.
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/ea/mdg/registry.rb', line 114 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).
Also registers the technology with
Lutaml::Model::GlobalRegister so it can be looked up via
the framework-level register API. This keeps MDG swapping
OCP-compliant: callers can query either Ea::Mdg::Registry
or Lutaml::Model::GlobalRegister to find loaded MDGs.
58 59 60 61 62 63 |
# File 'lib/ea/mdg/registry.rb', line 58 def register(document) technology = document.technology_name @documents.reject! { |d| d.technology_name == technology } @documents << document register_with_lutaml(technology, document) end |
#size ⇒ Object
78 79 80 |
# File 'lib/ea/mdg/registry.rb', line 78 def size @documents.size end |
#technology_names ⇒ Object
82 83 84 |
# File 'lib/ea/mdg/registry.rb', line 82 def technology_names @documents.map(&:technology_name) end |
#unregister(technology_name) ⇒ Object Also known as: remove
Remove an MDG Document by technology name. Also unregisters from Lutaml::Model::GlobalRegister.
67 68 69 70 71 |
# File 'lib/ea/mdg/registry.rb', line 67 def unregister(technology_name) @documents.reject! { |d| d.technology_name == technology_name } lutaml_register_id = lutaml_id_for(technology_name) Lutaml::Model::GlobalRegister.remove(lutaml_register_id) end |