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
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
40 41 42 43 44 45 46 47 48 49 |
# File 'lib/lutaml/xsd/spa/schema_serializer.rb', line 40 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.
34 35 36 |
# File 'lib/lutaml/xsd/spa/schema_serializer.rb', line 34 def config @config end |
#package ⇒ Object (readonly)
Returns the value of attribute package.
34 35 36 |
# File 'lib/lutaml/xsd/spa/schema_serializer.rb', line 34 def package @package end |
#repository ⇒ Object (readonly)
Returns the value of attribute repository.
34 35 36 |
# File 'lib/lutaml/xsd/spa/schema_serializer.rb', line 34 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.
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/lutaml/xsd/spa/schema_serializer.rb', line 57 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
84 85 86 87 |
# File 'lib/lutaml/xsd/spa/schema_serializer.rb', line 84 def to_json(pretty: true) data = serialize pretty ? JSON.pretty_generate(data) : JSON.generate(data) end |