Class: Ea::Export::Xsd::Generator

Inherits:
Object
  • Object
show all
Defined in:
lib/ea/export/xsd/generator.rb

Overview

Generates an XSD schema string from a parsed QEA model.

Pure: takes already-loaded ClassMapping and NamespaceRegistry instances. No file IO, no fixture-path coupling. The CLI layer is responsible for loading GMLClassMapping.xml and GMLNamespaces.xml from disk.

Defined Under Namespace

Classes: Classifier

Constant Summary collapse

XSD_NS =
"http://www.w3.org/2001/XMLSchema"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(class_mapping: ClassMapping.new, namespaces: NamespaceRegistry.new) ⇒ Generator

Returns a new instance of Generator.

Parameters:

  • class_mapping (ClassMapping) (defaults to: ClassMapping.new)

    type translation rules

  • namespaces (NamespaceRegistry) (defaults to: NamespaceRegistry.new)

    namespace declarations



21
22
23
24
25
# File 'lib/ea/export/xsd/generator.rb', line 21

def initialize(class_mapping: ClassMapping.new,
               namespaces: NamespaceRegistry.new)
  @class_mapping = class_mapping
  @namespaces = namespaces
end

Instance Attribute Details

#class_mappingObject (readonly)

Returns the value of attribute class_mapping.



17
18
19
# File 'lib/ea/export/xsd/generator.rb', line 17

def class_mapping
  @class_mapping
end

#namespacesObject (readonly)

Returns the value of attribute namespaces.



17
18
19
# File 'lib/ea/export/xsd/generator.rb', line 17

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.



29
30
31
32
# File 'lib/ea/export/xsd/generator.rb', line 29

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.

Parameters:

  • model (#collections)

    anything responding to #collections with a :packages and :objects collection (Ea::Qea::Database).

  • target_namespace (String)

    XSD targetNamespace

  • prefix (String) (defaults to: "tns")

    namespace prefix for the target

Returns:

  • (String)

    serialized XSD



40
41
42
43
44
# File 'lib/ea/export/xsd/generator.rb', line 40

def call(model, target_namespace:, prefix: "tns")
  doc = build_schema_doc(target_namespace, prefix)
  walk_model(model, doc)
  doc.to_xml(indent: 2)
end