Class: Lutaml::Xml::Schema::Xsd::SerializedSchema
- Inherits:
-
Model::Serializable
- Object
- Model::Serializable
- Lutaml::Xml::Schema::Xsd::SerializedSchema
- Defined in:
- lib/lutaml/xml/schema/xsd/serialized_schema.rb
Overview
Represents a serialized schema for storage in packages
Constant Summary
Constants included from Model::Serialize
Model::Serialize::DEFAULT_VALUE_MAP, Model::Serialize::INTERNAL_ATTRIBUTES, Model::Serialize::LAZY_EMPTY_COLLECTION
Instance Attribute Summary
Attributes included from Model::Serialize
#lutaml_parent, #lutaml_register, #lutaml_root
Class Method Summary collapse
-
.from_schema(file_path, schema) ⇒ SerializedSchema
Create from a parsed Schema object.
-
.serialize_attribute_groups(groups) ⇒ Object
Serialize attribute groups.
-
.serialize_elements(elements) ⇒ Object
Serialize elements.
-
.serialize_groups(groups) ⇒ Object
Serialize groups.
-
.serialize_types(types) ⇒ Object
Serialize type definitions to a hash.
Instance Method Summary collapse
-
#to_schema ⇒ Schema
Deserialize back to a Schema object.
Methods included from Model::Serialize
#attr_value, #attribute_exist?, #extract_register_id, included, #init_deserialization_state, #initialize, #key_exist?, #key_value, #method_missing, #prepare_instance_format_options, #pretty_print_instance_variables, register_format_mapping_method, register_from_format_method, register_to_format_method, #respond_to_missing?, #to_format, #to_yaml_hash, #using_default?, #using_default_for, #validate_attribute!, #validate_root_mapping!, #value_map, #value_set_for
Methods included from Model::Liquefiable
Methods included from Model::Validation
#format_element_sequences, #order_names, #validate, #validate!, #validate_helper, #validate_sequence!
Methods included from Model::ComparableModel
#already_compared?, #attributes_hash, #calculate_hash, #comparison_key, #eql?, #hash, included, #same_class?
Methods included from Model::Serialize::Builder
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Lutaml::Model::Serialize
Class Method Details
.from_schema(file_path, schema) ⇒ SerializedSchema
Create from a parsed Schema object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/lutaml/xml/schema/xsd/serialized_schema.rb', line 25 def self.from_schema(file_path, schema) # Serialize schema to JSON instead of YAML to avoid circular reference issues # We'll store the essential data that can be reconstructed schema_hash = { target_namespace: schema.target_namespace, element_form_default: schema.element_form_default, attribute_form_default: schema.attribute_form_default, version: schema.version, simple_types: serialize_types(schema.simple_type), complex_types: serialize_types(schema.complex_type), elements: serialize_elements(schema.element), attribute_groups: serialize_attribute_groups(schema.attribute_group), groups: serialize_groups(schema.group), } new( file_path: file_path, target_namespace: schema.target_namespace, schema_data: JSON.generate(schema_hash), ) end |
.serialize_attribute_groups(groups) ⇒ Object
Serialize attribute groups
147 148 149 150 151 |
# File 'lib/lutaml/xml/schema/xsd/serialized_schema.rb', line 147 def self.serialize_attribute_groups(groups) return [] unless groups groups.map { |g| { name: g.name } } end |
.serialize_elements(elements) ⇒ Object
Serialize elements
123 124 125 126 127 128 129 130 131 132 |
# File 'lib/lutaml/xml/schema/xsd/serialized_schema.rb', line 123 def self.serialize_elements(elements) return [] unless elements elements.map do |elem| { name: elem.name, type: elem.type, } end end |
.serialize_groups(groups) ⇒ Object
Serialize groups
165 166 167 168 169 |
# File 'lib/lutaml/xml/schema/xsd/serialized_schema.rb', line 165 def self.serialize_groups(groups) return [] unless groups groups.map { |g| { name: g.name } } end |
.serialize_types(types) ⇒ Object
Serialize type definitions to a hash
80 81 82 83 84 85 86 87 88 89 |
# File 'lib/lutaml/xml/schema/xsd/serialized_schema.rb', line 80 def self.serialize_types(types) return [] unless types types.map do |type| { name: type.name, class: type.class.name, } end end |
Instance Method Details
#to_schema ⇒ Schema
Deserialize back to a Schema object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/lutaml/xml/schema/xsd/serialized_schema.rb', line 49 def to_schema data = JSON.parse(schema_data) # Create a minimal Schema object with the essential data schema = Schema.new( target_namespace: data["target_namespace"], element_form_default: data["element_form_default"], attribute_form_default: data["attribute_form_default"], version: data["version"], ) # Reconstruct collections schema.instance_variable_set(:@simple_type, deserialize_types(data["simple_types"], :simple_type)) schema.instance_variable_set(:@complex_type, deserialize_types(data["complex_types"], :complex_type)) schema.instance_variable_set(:@element, deserialize_elements(data["elements"])) schema.instance_variable_set(:@attribute_group, deserialize_attribute_groups(data["attribute_groups"])) schema.instance_variable_set(:@group, deserialize_groups(data["groups"])) schema end |