Class: Lutaml::Xsd::Spa::SchemaSerializer Abstract
- Inherits:
-
Object
- Object
- Lutaml::Xsd::Spa::SchemaSerializer
- Includes:
- Utils::ExtractEnumeration
- Defined in:
- lib/lutaml/xsd/spa/schema_serializer.rb
Overview
Subclass and override template methods to customize serialization
Base class for schema serializers (Template Method Pattern)
Defines the overall algorithm for serializing XSD schema repositories into a format suitable for SPA documentation. Subclasses can override specific steps to customize the serialization process.
The serialization process follows these steps:
-
Build metadata
-
Serialize all schemas
-
Build search index
-
Assemble final structure
Constant Summary collapse
- MERGEABLE_CONTENT_FIELDS =
Fields to merge when combining schemas with the same targetNamespace
%i[ elements complex_types simple_types attributes groups attribute_groups ].freeze
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#package ⇒ Object
readonly
Returns the value of attribute package.
-
#repository ⇒ Object
readonly
Returns the value of attribute repository.
Instance Method Summary collapse
-
#initialize(repository_or_package, config = {}) ⇒ SchemaSerializer
constructor
Initialize schema serializer.
-
#serialize ⇒ Hash
Serialize repository to data structure (template method).
-
#to_json(pretty: true) ⇒ String
Convert serialized data to JSON string.
Methods included from Utils::ExtractEnumeration
#extract_enumeration_default, #extract_enumeration_values
Constructor Details
#initialize(repository_or_package, config = {}) ⇒ SchemaSerializer
Initialize schema serializer
50 51 52 53 54 55 56 57 58 59 |
# File 'lib/lutaml/xsd/spa/schema_serializer.rb', line 50 def initialize(repository_or_package, config = {}) if repository_or_package.is_a?(SchemaRepositoryPackage) @package = repository_or_package @repository = repository_or_package.repository else @repository = repository_or_package @package = nil end @config = config end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
44 45 46 |
# File 'lib/lutaml/xsd/spa/schema_serializer.rb', line 44 def config @config end |
#package ⇒ Object (readonly)
Returns the value of attribute package.
44 45 46 |
# File 'lib/lutaml/xsd/spa/schema_serializer.rb', line 44 def package @package end |
#repository ⇒ Object (readonly)
Returns the value of attribute repository.
44 45 46 |
# File 'lib/lutaml/xsd/spa/schema_serializer.rb', line 44 def repository @repository end |
Instance Method Details
#serialize ⇒ Hash
Serialize repository to data structure (template method)
This method defines the overall algorithm for serialization. Subclasses can override individual steps as needed.
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/lutaml/xsd/spa/schema_serializer.rb', line 67 def serialize = # Convert SpaMetadata model to hash for JSON serialization # SpaMetadata.to_hash returns string keys, but we need symbol keys for compatibility = if .respond_to?(:to_hash) hash = .to_hash # Convert string keys to symbols for backward compatibility hash.to_h do |k, v| [k.is_a?(String) ? k.to_sym : k, v] end elsif .respond_to?(:to_h) .to_h else end { metadata: , schemas: serialize_schemas, namespaces: build_namespaces, index: build_index, } end |
#to_json(pretty: true) ⇒ String
Convert serialized data to JSON string
94 95 96 97 |
# File 'lib/lutaml/xsd/spa/schema_serializer.rb', line 94 def to_json(pretty: true) data = serialize pretty ? JSON.pretty_generate(data) : JSON.generate(data) end |