Class: Ea::Export::Xsd::Generator
- Inherits:
-
Object
- Object
- Ea::Export::Xsd::Generator
- Defined in:
- lib/ea/export/xsd/generator.rb
Overview
Generates an XSD schema string from a parsed QEA model.
Uses ClassMapping to translate UML class names to GML types
and NamespaceRegistry to declare target namespaces. Walks the
model's classifiers and emits <xs:element> + <xs:complexType>
pairs.
Both class_mapping and namespaces default to the EA-bundled GML fixtures when present, so callers can do Ea::Export::Xsd::Generator.call(model, target_namespace: ...) without manually loading XML fixtures.
Defined Under Namespace
Classes: Classifier
Constant Summary collapse
- XSD_NS =
"http://www.w3.org/2001/XMLSchema"- DEFAULT_MAPPING_PATH =
"spec/fixtures/mdg/ea_config/gml/GMLClassMapping.xml".freeze
- DEFAULT_NAMESPACES_PATH =
"spec/fixtures/mdg/ea_config/gml/GMLNamespaces.xml".freeze
Instance Attribute Summary collapse
-
#class_mapping ⇒ Object
readonly
Returns the value of attribute class_mapping.
-
#namespaces ⇒ Object
readonly
Returns the value of attribute namespaces.
Class Method Summary collapse
-
.call(model, target_namespace: "http://example.com/xsd", prefix: "tns", **opts) ⇒ Object
Class-method shortcut.
Instance Method Summary collapse
-
#call(model, target_namespace:, prefix: "tns") ⇒ String
Generate an XSD schema for the given model.
-
#initialize(class_mapping: nil, namespaces: nil) ⇒ Generator
constructor
A new instance of Generator.
Constructor Details
#initialize(class_mapping: nil, namespaces: nil) ⇒ Generator
Returns a new instance of Generator.
27 28 29 30 |
# File 'lib/ea/export/xsd/generator.rb', line 27 def initialize(class_mapping: nil, namespaces: nil) @class_mapping = class_mapping || ClassMapping.from_path(DEFAULT_MAPPING_PATH) @namespaces = namespaces || NamespaceRegistry.from_path(DEFAULT_NAMESPACES_PATH) end |
Instance Attribute Details
#class_mapping ⇒ Object (readonly)
Returns the value of attribute class_mapping.
25 26 27 |
# File 'lib/ea/export/xsd/generator.rb', line 25 def class_mapping @class_mapping end |
#namespaces ⇒ Object (readonly)
Returns the value of attribute namespaces.
25 26 27 |
# File 'lib/ea/export/xsd/generator.rb', line 25 def namespaces @namespaces end |
Class Method Details
.call(model, target_namespace: "http://example.com/xsd", prefix: "tns", **opts) ⇒ Object
Class-method shortcut. Accepts the same options as #initialize via keyword args.
34 35 36 37 |
# File 'lib/ea/export/xsd/generator.rb', line 34 def self.call(model, target_namespace: "http://example.com/xsd", prefix: "tns", **opts) new(**opts).call(model, target_namespace: target_namespace, prefix: prefix) end |
Instance Method Details
#call(model, target_namespace:, prefix: "tns") ⇒ String
Generate an XSD schema for the given model.
45 46 47 48 49 |
# File 'lib/ea/export/xsd/generator.rb', line 45 def call(model, target_namespace:, prefix: "tns") doc = build_schema_doc(target_namespace, prefix) walk_model(model, doc) doc.to_xml(indent: 2) end |