lutaml-model 0.8.186 → 0.8.188
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/dependent-repos-tools-informational.json +8 -0
- data/.github/workflows/dependent-repos-tools.json +1 -5
- data/.github/workflows/dependent-tests.yml +26 -2
- data/Gemfile +2 -0
- data/Rakefile +6 -0
- data/exe/lutaml-lml-lsp +11 -0
- data/lib/compat/opal/generate_boot.rb +12 -5
- data/lib/compat/opal/lutaml_model_boot.rb +96 -4
- data/lib/lutaml/lml/association_label_resolver.rb +52 -0
- data/lib/lutaml/lml/data_processor/attribute_processing.rb +133 -0
- data/lib/lutaml/lml/data_processor/collection_processing.rb +37 -0
- data/lib/lutaml/lml/data_processor/instance_processing.rb +77 -0
- data/lib/lutaml/lml/data_processor/value_declaration_processing.rb +70 -0
- data/lib/lutaml/lml/data_processor/value_processing.rb +103 -0
- data/lib/lutaml/lml/data_processor/view_processing.rb +26 -0
- data/lib/lutaml/lml/data_processor.rb +66 -0
- data/lib/lutaml/lml/diagnostic.rb +149 -0
- data/lib/lutaml/lml/document_builder.rb +486 -0
- data/lib/lutaml/lml/entity_types.rb +31 -0
- data/lib/lutaml/lml/executor/adapter_helpers.rb +45 -0
- data/lib/lutaml/lml/executor/condition_evaluator.rb +175 -0
- data/lib/lutaml/lml/executor/csv_adapter.rb +89 -0
- data/lib/lutaml/lml/executor/format_adapter.rb +54 -0
- data/lib/lutaml/lml/executor/xml_adapter.rb +102 -0
- data/lib/lutaml/lml/executor.rb +96 -0
- data/lib/lutaml/lml/format/adapter/document.rb +11 -0
- data/lib/lutaml/lml/format/adapter/mapping.rb +31 -0
- data/lib/lutaml/lml/format/adapter/standard_adapter.rb +164 -0
- data/lib/lutaml/lml/format/adapter/transform.rb +11 -0
- data/lib/lutaml/lml/format.rb +34 -0
- data/lib/lutaml/lml/formatter/base.rb +81 -0
- data/lib/lutaml/lml/formatter/canonical.rb +738 -0
- data/lib/lutaml/lml/formatter.rb +11 -0
- data/lib/lutaml/lml/grammar/lml.artifact.json +14993 -0
- data/lib/lutaml/lml/grammar/lml.parg +389 -0
- data/lib/lutaml/lml/grammar.rb +60 -0
- data/lib/lutaml/lml/has_attributes.rb +14 -0
- data/lib/lutaml/lml/import_resolver.rb +96 -0
- data/lib/lutaml/lml/layout/engine.rb +17 -0
- data/lib/lutaml/lml/layout.rb +9 -0
- data/lib/lutaml/lml/literal_value.rb +32 -0
- data/lib/lutaml/lml/lsp/conversions.rb +78 -0
- data/lib/lutaml/lml/lsp/keywords.rb +43 -0
- data/lib/lutaml/lml/lsp/server.rb +380 -0
- data/lib/lutaml/lml/lsp/store.rb +68 -0
- data/lib/lutaml/lml/lsp/transport.rb +53 -0
- data/lib/lutaml/lml/lsp.rb +16 -0
- data/lib/lutaml/lml/model_compiler/enums.rb +170 -0
- data/lib/lutaml/lml/model_compiler/hydration.rb +122 -0
- data/lib/lutaml/lml/model_compiler/serialization_mappings.rb +188 -0
- data/lib/lutaml/lml/model_compiler/string_formats.rb +42 -0
- data/lib/lutaml/lml/model_compiler/validation.rb +65 -0
- data/lib/lutaml/lml/model_compiler.rb +329 -0
- data/lib/lutaml/lml/models/action.rb +10 -0
- data/lib/lutaml/lml/models/association.rb +31 -0
- data/lib/lutaml/lml/models/cardinality.rb +10 -0
- data/lib/lutaml/lml/models/collection.rb +11 -0
- data/lib/lutaml/lml/models/constraint.rb +25 -0
- data/lib/lutaml/lml/models/data_type.rb +43 -0
- data/lib/lutaml/lml/models/derived_field.rb +14 -0
- data/lib/lutaml/lml/models/diagram.rb +22 -0
- data/lib/lutaml/lml/models/document.rb +86 -0
- data/lib/lutaml/lml/models/enum.rb +40 -0
- data/lib/lutaml/lml/models/fidelity.rb +10 -0
- data/lib/lutaml/lml/models/group.rb +11 -0
- data/lib/lutaml/lml/models/instance.rb +28 -0
- data/lib/lutaml/lml/models/instance_collection.rb +18 -0
- data/lib/lutaml/lml/models/instances_export.rb +10 -0
- data/lib/lutaml/lml/models/instances_import.rb +11 -0
- data/lib/lutaml/lml/models/mapping.rb +15 -0
- data/lib/lutaml/lml/models/mapping_rule.rb +16 -0
- data/lib/lutaml/lml/models/member_field.rb +16 -0
- data/lib/lutaml/lml/models/namespace.rb +18 -0
- data/lib/lutaml/lml/models/operation.rb +28 -0
- data/lib/lutaml/lml/models/operation_parameter.rb +12 -0
- data/lib/lutaml/lml/models/package.rb +28 -0
- data/lib/lutaml/lml/models/primitive_type.rb +35 -0
- data/lib/lutaml/lml/models/reference.rb +23 -0
- data/lib/lutaml/lml/models/serialization_mapping.rb +21 -0
- data/lib/lutaml/lml/models/string_format.rb +16 -0
- data/lib/lutaml/lml/models/top_element_attribute.rb +118 -0
- data/lib/lutaml/lml/models/uml_class.rb +87 -0
- data/lib/lutaml/lml/models/value.rb +17 -0
- data/lib/lutaml/lml/models/view_filter.rb +11 -0
- data/lib/lutaml/lml/models/view_import.rb +11 -0
- data/lib/lutaml/lml/parser.rb +19 -0
- data/lib/lutaml/lml/pipeline.rb +73 -0
- data/lib/lutaml/lml/positioned.rb +13 -0
- data/lib/lutaml/lml/preprocessor.rb +132 -0
- data/lib/lutaml/lml/quoting.rb +60 -0
- data/lib/lutaml/lml/source.rb +49 -0
- data/lib/lutaml/lml/source_position.rb +20 -0
- data/lib/lutaml/lml/symbol_index.rb +202 -0
- data/lib/lutaml/lml/transform.rb +119 -0
- data/lib/lutaml/lml/types/text_type.rb +28 -0
- data/lib/lutaml/lml/types.rb +10 -0
- data/lib/lutaml/lml/validator.rb +460 -0
- data/lib/lutaml/lml/view_resolution.rb +32 -0
- data/lib/lutaml/lml/view_resolver.rb +48 -0
- data/lib/lutaml/lml/yaml_parser.rb +17 -0
- data/lib/lutaml/lml.rb +130 -0
- data/lib/lutaml/model/adapter_resolver.rb +21 -2
- data/lib/lutaml/model/config.rb +22 -0
- data/lib/lutaml/model/serialize/format_conversion.rb +8 -6
- data/lib/lutaml/model/version.rb +1 -1
- data/lib/lutaml/xml/adapter/base_adapter.rb +26 -0
- data/lib/lutaml/xml/adapter/moxml_adapter.rb +49 -0
- data/lib/lutaml/xml/adapter/xml_parser.rb +4 -4
- data/lib/lutaml/xml/adapter/xml_serializer.rb +1 -1
- data/lib/lutaml/xml/adapter.rb +5 -0
- data/lib/lutaml/xml/adapter_loader.rb +5 -0
- data/lib/lutaml/xml/format.rb +23 -2
- data/lib/lutaml/xml/leptris/native_emission.rb +6 -1
- data/lib/lutaml/xml/leptris/plan_serializer.rb +5 -1
- data/lib/lutaml/xml/parse_session.rb +8 -1
- data/lib/lutaml/xml/schema/builder/moxml.rb +1 -1
- data/lib/lutaml/xml/schema/builder.rb +1 -1
- data/lib/lutaml/xml/schema/relaxng_schema.rb +1 -1
- data/lib/lutaml/xml/schema/vc_namespace.rb +24 -0
- data/lib/lutaml/xml/schema/xsd/any.rb +4 -0
- data/lib/lutaml/xml/schema/xsd/any_attribute.rb +4 -0
- data/lib/lutaml/xml/schema/xsd/base.rb +7 -0
- data/lib/lutaml/xml/schema/xsd/open_content.rb +2 -0
- data/lib/lutaml/xml/schema/xsd/restriction_simple_type.rb +3 -0
- data/lib/lutaml/xml/schema/xsd/schema.rb +38 -0
- data/lib/lutaml/xml/schema/xsd/schema_validator.rb +1 -1
- data/lib/lutaml/xml/schema/xsd.rb +1 -0
- data/lib/lutaml/xml/schema/xsd_schema.rb +1 -1
- data/lib/lutaml/xml/serialization/format_conversion.rb +6 -0
- data/lib/lutaml/xml/xsd_validator.rb +1 -1
- data/lutaml-model.gemspec +2 -0
- data/spec/lml/fixtures/dsl/broken_diagram.lutaml +34 -0
- data/spec/lml/fixtures/dsl/diagram.lutaml +4 -0
- data/spec/lml/fixtures/dsl/diagram_attributes.lutaml +6 -0
- data/spec/lml/fixtures/dsl/diagram_blank_definion.lutaml +6 -0
- data/spec/lml/fixtures/dsl/diagram_blank_entities.lutaml +8 -0
- data/spec/lml/fixtures/dsl/diagram_class_assocation.lutaml +29 -0
- data/spec/lml/fixtures/dsl/diagram_class_fields.lutaml +25 -0
- data/spec/lml/fixtures/dsl/diagram_commented_includes.lutaml +5 -0
- data/spec/lml/fixtures/dsl/diagram_comments.lutaml +28 -0
- data/spec/lml/fixtures/dsl/diagram_concept_model.lutaml +132 -0
- data/spec/lml/fixtures/dsl/diagram_data_types.lutaml +44 -0
- data/spec/lml/fixtures/dsl/diagram_definitions.lutaml +25 -0
- data/spec/lml/fixtures/dsl/diagram_includes.lutaml +6 -0
- data/spec/lml/fixtures/dsl/diagram_multiply_classes.lutaml +7 -0
- data/spec/lml/fixtures/dsl/diagram_non_existing_include.lutaml +6 -0
- data/spec/lml/fixtures/dsl/shared.lutaml +5 -0
- data/spec/lml/fixtures/dsl/shared1.lutaml +4 -0
- data/spec/lml/fixtures/generated_dot/AddressClassProfile.dot +170 -0
- data/spec/lml/fixtures/generated_dot/AddressProfile.dot +34 -0
- data/spec/lml/fixtures/generated_dot/address_class_profile_with_associations.dot +127 -0
- data/spec/lml/fixtures/generated_dot/address_profile_with_associations.dot +28 -0
- data/spec/lml/fixtures/generated_dot/document.dot +28 -0
- data/spec/lml/fixtures/generated_dot/document.dot.backup +33 -0
- data/spec/lml/fixtures/generated_dot/document_with_fidelity.dot +27 -0
- data/spec/lml/fixtures/lml/data_s102_check.lml +79 -0
- data/spec/lml/fixtures/lml/data_s158_metadata.lml +28 -0
- data/spec/lml/fixtures/lml/iho_data_models.lml +59 -0
- data/spec/lml/fixtures/lml/iho_s102_check.lml +101 -0
- data/spec/lml/fixtures/mixed_lml/diagram.lml +26 -0
- data/spec/lml/fixtures/mixed_lml/instances.lml +72 -0
- data/spec/lml/fixtures/mixed_lml/model.lml +30 -0
- data/spec/lml/fixtures/real_world/basicdoc-models/AdmonitionType.lutaml +32 -0
- data/spec/lml/fixtures/real_world/basicdoc-models/BasicBlock.lutaml +11 -0
- data/spec/lml/fixtures/real_world/basicdoc-models/BasicDocument.lutaml +41 -0
- data/spec/lml/fixtures/real_world/basicdoc-models/BasicSection.lutaml +38 -0
- data/spec/lml/fixtures/real_world/basicdoc-models/BibliographicItem.lutaml +6 -0
- data/spec/lml/fixtures/real_world/basicdoc-models/FigureBlock.lutaml +65 -0
- data/spec/lml/fixtures/real_world/basicdoc-models/FormattedString.lutaml +12 -0
- data/spec/lml/fixtures/real_world/basicdoc-models/List.lutaml +12 -0
- data/spec/lml/fixtures/real_world/basicdoc-models/OrderedListType.lutaml +32 -0
- data/spec/lml/fixtures/real_world/basicdoc-models/Signature.lutaml +22 -0
- data/spec/lml/fixtures/real_world/basicdoc-models/String.lutaml +2 -0
- data/spec/lml/fixtures/real_world/basicdoc-models/TableBlock.lutaml +60 -0
- data/spec/lml/fixtures/real_world/basicdoc-models/TextElement.lutaml +13 -0
- data/spec/lml/fixtures/real_world/basicdoc-models/Uri.lutaml +7 -0
- data/spec/lml/fixtures/real_world/metanorma-model-iso/BibliographicItem.lutaml +4 -0
- data/spec/lml/fixtures/real_world/metanorma-model-iso/IsoAdmonitionType.lutaml +31 -0
- data/spec/lml/fixtures/real_world/metanorma-model-iso/IsoBibDataExtensionType.lutaml +40 -0
- data/spec/lml/fixtures/real_world/metanorma-model-iso/IsoSections.lutaml +30 -0
- data/spec/lml/fixtures/real_world/metanorma-model-iso/IsoStandardDocument.lutaml +46 -0
- data/spec/lml/fixtures/real_world/metanorma-model-iso/IsoTerm.lutaml +20 -0
- data/spec/lml/fixtures/real_world/metanorma-model-iso/StandardBibDataExtensionType.lutaml +2 -0
- data/spec/lml/fixtures/real_world/metanorma-model-iso/StandardDocument.lutaml +2 -0
- data/spec/lml/fixtures/rs3001/01_class_tail_comment.lml +5 -0
- data/spec/lml/fixtures/rs3001/02_definition_block.lml +9 -0
- data/spec/lml/fixtures/rs3001/03_package_ceramics.lml +20 -0
- data/spec/lml/fixtures/rs3001/04_attribute_definition_form.lml +10 -0
- data/spec/lml/fixtures/rs3001/05_attribute_cardinality_unbounded.lml +10 -0
- data/spec/lml/fixtures/rs3001/06_attribute_values_set.lml +10 -0
- data/spec/lml/fixtures/rs3001/07_attribute_pattern.lml +10 -0
- data/spec/lml/fixtures/rs3001/08_attribute_default_colon.lml +15 -0
- data/spec/lml/fixtures/rs3001/09_value_porcelain.lml +9 -0
- data/spec/lml/fixtures/rs3001/10_enum_glaze_technique.lml +19 -0
- data/spec/lml/fixtures/rs3001/11_enum_values_as_instances.lml +29 -0
- data/spec/lml/fixtures/rs3001/12_instance_named.lml +13 -0
- data/spec/lml/fixtures/rs3001/13_instances_collection_refs.lml +11 -0
- data/spec/lml/fixtures/rs3001/14_require_models.lml +7 -0
- data/spec/lml/fixtures/rs3001/15_comment_line.lml +1 -0
- data/spec/lml/fixtures/rs3001/16_comment_tail.lml +5 -0
- data/spec/lml/fixtures/rs3001/17_comment_documented_class.lml +5 -0
- data/spec/lml/fixtures/rs3001/18_comment_block.lml +4 -0
- data/spec/lml/fixtures/rs3001/19_top_level_instance_definition.lml +21 -0
- data/spec/lml/fixtures/rs3001/20_instance_typed_definition.lml +22 -0
- data/spec/lml/fixtures/rs3001/21_instance_collection_studios.lml +19 -0
- data/spec/lml/fixtures/rs3001/22_instance_collection_tiles.lml +15 -0
- data/spec/lml/fixtures/rs3001/23_reference_cross_collection.lml +11 -0
- data/spec/lml/fixtures/rs3001/24_null_and_empty.lml +15 -0
- data/spec/lml/fixtures/rs3001/25_string_escapes.lml +23 -0
- data/spec/lml/fixtures/rs3001/26_quoted_keys.lml +7 -0
- data/spec/lml/fixtures/test.lutaml +20 -0
- data/spec/lml/fixtures/test_data/components.csv +4 -0
- data/spec/lml/fixtures/test_data/products.xml +18 -0
- data/spec/lml/fixtures/uml/address_class_profile_with_associations.yml +58 -0
- data/spec/lml/fixtures/uml/address_profile_with_associations.yml +31 -0
- data/spec/lml/fixtures/uml/association.yml +11 -0
- data/spec/lml/fixtures/uml/class.yml +28 -0
- data/spec/lml/fixtures/uml/data_type.yml +30 -0
- data/spec/lml/fixtures/uml/diagram.yml +7 -0
- data/spec/lml/fixtures/uml/document.yml +44 -0
- data/spec/lml/fixtures/uml/document_with_fidelity.yml +47 -0
- data/spec/lml/fixtures/uml/enum.yml +14 -0
- data/spec/lml/fixtures/uml/operation.yml +8 -0
- data/spec/lml/fixtures/uml/package.yml +10 -0
- data/spec/lml/fixtures/uml/top_element.yml +11 -0
- data/spec/lml/fixtures/uml/top_element_attribute.yml +10 -0
- data/spec/lml/fixtures/uml/trigger.yml +12 -0
- data/spec/lml/fixtures/uml/value.yml +8 -0
- data/spec/lml/fixtures/view/cycle_a.lutaml +3 -0
- data/spec/lml/fixtures/view/cycle_b.lutaml +3 -0
- data/spec/lml/fixtures/view/import_model.lutaml +3 -0
- data/spec/lml/fixtures/view/import_view.lutaml +3 -0
- data/spec/lml/fixtures/view/import_with_hide.lutaml +4 -0
- data/spec/lml/fixtures/view/import_with_show.lutaml +4 -0
- data/spec/lml/fixtures/view/models/bar.lutaml +3 -0
- data/spec/lml/fixtures/view/models/baz.lutaml +3 -0
- data/spec/lml/fixtures/view/models/foo.lutaml +4 -0
- data/spec/lml/integration/instance_import_export_spec.rb +102 -0
- data/spec/lml/lml_spec_setup.rb +25 -0
- data/spec/lml/lutaml/lml/association_label_resolver_spec.rb +139 -0
- data/spec/lml/lutaml/lml/data_processor_spec.rb +274 -0
- data/spec/lml/lutaml/lml/declarations_spec.rb +337 -0
- data/spec/lml/lutaml/lml/document_builder_registry_spec.rb +52 -0
- data/spec/lml/lutaml/lml/document_builder_spec.rb +99 -0
- data/spec/lml/lutaml/lml/element_visibility_spec.rb +128 -0
- data/spec/lml/lutaml/lml/entity_types_spec.rb +56 -0
- data/spec/lml/lutaml/lml/enum_spec.rb +77 -0
- data/spec/lml/lutaml/lml/executor/adapter_helpers_spec.rb +96 -0
- data/spec/lml/lutaml/lml/executor/condition_evaluator_spec.rb +393 -0
- data/spec/lml/lutaml/lml/executor/csv_adapter_spec.rb +151 -0
- data/spec/lml/lutaml/lml/executor/format_adapter_spec.rb +31 -0
- data/spec/lml/lutaml/lml/executor/xml_adapter_spec.rb +201 -0
- data/spec/lml/lutaml/lml/executor_spec.rb +71 -0
- data/spec/lml/lutaml/lml/format_adapter_spec.rb +272 -0
- data/spec/lml/lutaml/lml/format_autoload_spec.rb +31 -0
- data/spec/lml/lutaml/lml/grammar_spec.rb +581 -0
- data/spec/lml/lutaml/lml/has_attributes_spec.rb +54 -0
- data/spec/lml/lutaml/lml/import_resolver_spec.rb +116 -0
- data/spec/lml/lutaml/lml/instance_hydration_spec.rb +178 -0
- data/spec/lml/lutaml/lml/lsp/server_spec.rb +285 -0
- data/spec/lml/lutaml/lml/model_compiler_spec.rb +406 -0
- data/spec/lml/lutaml/lml/models/association_spec.rb +40 -0
- data/spec/lml/lutaml/lml/models/collection_spec.rb +27 -0
- data/spec/lml/lutaml/lml/models/data_type_spec.rb +34 -0
- data/spec/lml/lutaml/lml/models/diagram_spec.rb +18 -0
- data/spec/lml/lutaml/lml/models/document_spec.rb +64 -0
- data/spec/lml/lutaml/lml/models/enum_spec.rb +42 -0
- data/spec/lml/lutaml/lml/models/inheritance_spec.rb +77 -0
- data/spec/lml/lutaml/lml/models/instance_collection_spec.rb +62 -0
- data/spec/lml/lutaml/lml/models/instance_spec.rb +81 -0
- data/spec/lml/lutaml/lml/models/instances_export_spec.rb +23 -0
- data/spec/lml/lutaml/lml/models/instances_import_spec.rb +28 -0
- data/spec/lml/lutaml/lml/models/package_spec.rb +26 -0
- data/spec/lml/lutaml/lml/models/primitive_type_spec.rb +34 -0
- data/spec/lml/lutaml/lml/models/top_element_attribute_spec.rb +153 -0
- data/spec/lml/lutaml/lml/models/uml_class_spec.rb +70 -0
- data/spec/lml/lutaml/lml/models_version_spec.rb +27 -0
- data/spec/lml/lutaml/lml/operations_spec.rb +59 -0
- data/spec/lml/lutaml/lml/parser_spec.rb +348 -0
- data/spec/lml/lutaml/lml/pipeline_spec.rb +93 -0
- data/spec/lml/lutaml/lml/preprocessor_spec.rb +174 -0
- data/spec/lml/lutaml/lml/property_laws_spec.rb +344 -0
- data/spec/lml/lutaml/lml/real_world_spec.rb +191 -0
- data/spec/lml/lutaml/lml/reference_spec.rb +64 -0
- data/spec/lml/lutaml/lml/round_trip_spec.rb +457 -0
- data/spec/lml/lutaml/lml/rs3001_corpus_spec.rb +83 -0
- data/spec/lml/lutaml/lml/rs3001_syntax_spec.rb +77 -0
- data/spec/lml/lutaml/lml/serialization_mapping_spec.rb +127 -0
- data/spec/lml/lutaml/lml/source_spec.rb +62 -0
- data/spec/lml/lutaml/lml/transform_spec.rb +37 -0
- data/spec/lml/lutaml/lml/types/text_type_spec.rb +43 -0
- data/spec/lml/lutaml/lml/validator_spec.rb +238 -0
- data/spec/lml/lutaml/lml/view_resolver_spec.rb +78 -0
- data/spec/lml/lutaml/lml/view_spec.rb +112 -0
- data/spec/lml/lutaml/parsers/dsl_spec.rb +275 -0
- data/spec/lml/lutaml/parsers/yaml_spec.rb +52 -0
- data/spec/lml/lutaml/qualified_type_spec.rb +33 -0
- data/spec/lutaml/model/adapter_type_unset_restore_spec.rb +61 -0
- data/spec/lutaml/model/custom_bibtex_adapter_spec.rb +4 -1
- data/spec/lutaml/xml/adapter/moxml_lane_spec.rb +112 -0
- data/spec/lutaml/xml/adapter_metadata_default_spec.rb +21 -2
- data/spec/lutaml/xml/adapter_moxml_engine_spec.rb +57 -0
- data/spec/lutaml/xml/leptris/native_emission_plain_model_spec.rb +50 -0
- data/spec/lutaml/xml/plain_model_mapping_resolution_spec.rb +88 -0
- data/spec/lutaml/xml/schema/xsd/vc_versioning_spec.rb +49 -0
- data/spec/lutaml/xml/schema/xsd/xsd_11_constructs_spec.rb +83 -0
- metadata +286 -2
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "lutaml/lml/quoting"
|
|
4
|
+
|
|
5
|
+
module Lutaml
|
|
6
|
+
module Lml
|
|
7
|
+
module Format
|
|
8
|
+
module Adapter
|
|
9
|
+
# Serializes instance data to and from LML instance syntax on
|
|
10
|
+
# behalf of the lutaml-model format registry (to_lml/from_lml on
|
|
11
|
+
# compiled classes).
|
|
12
|
+
class StandardAdapter < Document
|
|
13
|
+
TYPE_KEY = "__type__"
|
|
14
|
+
|
|
15
|
+
include Lutaml::Lml::Quoting
|
|
16
|
+
|
|
17
|
+
def self.parse(data, _options = {})
|
|
18
|
+
return data if data.is_a?(Hash)
|
|
19
|
+
|
|
20
|
+
input = data.is_a?(IO) ? data : StringIO.new(data.to_s)
|
|
21
|
+
doc = Lutaml::Lml.parse_document(input)
|
|
22
|
+
instance_to_hash(doc.instance)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def to_lml(_options = {})
|
|
26
|
+
attrs = @attributes.dup
|
|
27
|
+
type_name = attrs.delete(TYPE_KEY) || "Data"
|
|
28
|
+
body = hash_to_lml_body(attrs)
|
|
29
|
+
"instance #{type_name} {\n#{body}\n}"
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def self.instance_to_hash(instance)
|
|
33
|
+
return nil unless instance
|
|
34
|
+
|
|
35
|
+
hash = {}
|
|
36
|
+
hash[TYPE_KEY] = instance.type if instance.type
|
|
37
|
+
|
|
38
|
+
instance.each_attribute do |name, value, nested|
|
|
39
|
+
if nested.any?
|
|
40
|
+
hashes = nested.map { |i| instance_to_hash(i) }
|
|
41
|
+
hash[name] = nested.one? ? hashes.first : hashes
|
|
42
|
+
elsif value.is_a?(Array)
|
|
43
|
+
hash[name] = value.map { |v| primitive_value(v) }
|
|
44
|
+
elsif !value.nil?
|
|
45
|
+
hash[name] = primitive_value(value)
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
hash.merge!(instance_to_hash(instance.instance)) if instance.instance
|
|
50
|
+
|
|
51
|
+
hash
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def self.primitive_value(val)
|
|
55
|
+
case val
|
|
56
|
+
when TrueClass, FalseClass, Integer, Float then val
|
|
57
|
+
else val.to_s
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
private_class_method :primitive_value
|
|
61
|
+
|
|
62
|
+
def hash_to_lml_body(hash, indent = 1)
|
|
63
|
+
lines = []
|
|
64
|
+
prefix = " " * indent
|
|
65
|
+
|
|
66
|
+
hash.each do |key, value|
|
|
67
|
+
next if key == TYPE_KEY
|
|
68
|
+
|
|
69
|
+
lines << format_value(prefix, key, value, indent)
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
lines.join("\n")
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def format_key(key)
|
|
76
|
+
quote_scalar(key)
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
def format_value(prefix, key, value, indent)
|
|
80
|
+
key = format_key(key)
|
|
81
|
+
return "#{prefix}#{key} = ref:(#{value[:reference]})" if reference_value?(value)
|
|
82
|
+
|
|
83
|
+
case value
|
|
84
|
+
when Array
|
|
85
|
+
format_array(prefix, key, value, indent)
|
|
86
|
+
when Hash
|
|
87
|
+
format_nested(prefix, key, value, indent)
|
|
88
|
+
when Float
|
|
89
|
+
"#{prefix}#{key} = #{number_scalar(value)}"
|
|
90
|
+
when TrueClass, FalseClass, Integer
|
|
91
|
+
"#{prefix}#{key} = #{value}"
|
|
92
|
+
else
|
|
93
|
+
"#{prefix}#{key} = #{quote_value(value)}"
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
def format_array(prefix, key, items, indent)
|
|
98
|
+
elements = items.map do |item|
|
|
99
|
+
if reference_value?(item)
|
|
100
|
+
" ref:(#{item[:reference]})"
|
|
101
|
+
else
|
|
102
|
+
case item
|
|
103
|
+
when Hash
|
|
104
|
+
format_nested_instance(item, indent + 1)
|
|
105
|
+
else
|
|
106
|
+
" #{quote_value(item)}"
|
|
107
|
+
end
|
|
108
|
+
end
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
inner = elements.join(",\n")
|
|
112
|
+
"#{prefix}#{key} = [\n#{inner}\n#{prefix}]"
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
def format_nested(prefix, key, hash, indent)
|
|
116
|
+
type_name = hash.fetch(TYPE_KEY, "")
|
|
117
|
+
inner = hash_to_lml_body(hash, indent + 1)
|
|
118
|
+
type_clause = type_name.empty? ? "" : " #{type_name}"
|
|
119
|
+
"#{prefix}#{key} = instance#{type_clause} {\n#{inner}\n#{prefix}}"
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
def format_nested_instance(hash, indent)
|
|
123
|
+
prefix = " " * indent
|
|
124
|
+
type_name = hash.fetch(TYPE_KEY, "")
|
|
125
|
+
inner = hash_to_lml_body(hash, indent + 1)
|
|
126
|
+
type_clause = type_name.empty? ? "" : " #{type_name}"
|
|
127
|
+
"#{prefix}instance#{type_clause} {\n#{inner}\n#{prefix}}"
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
# RS 3001 par. Value type: a `reference` map is the wire form of a
|
|
131
|
+
# reference literal; it emits as `ref:(path)`, never as a nested
|
|
132
|
+
# instance.
|
|
133
|
+
def reference_value?(value)
|
|
134
|
+
value.is_a?(Hash) && value.keys == [:reference]
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
def quote_value(val)
|
|
138
|
+
return number_scalar(val) if val.is_a?(Float)
|
|
139
|
+
return val.to_s if val.is_a?(Numeric) || val.is_a?(TrueClass) || val.is_a?(FalseClass)
|
|
140
|
+
|
|
141
|
+
# RS 3001 §String values: escape backslash and double quote;
|
|
142
|
+
# every value is representable in double quotes. A bare word
|
|
143
|
+
# is only safe when the parser reads it back as the same
|
|
144
|
+
# string — `null`, booleans, and digit-leading tokens are
|
|
145
|
+
# data literals (and digit-led words do not re-parse).
|
|
146
|
+
str = val.to_s
|
|
147
|
+
return str if safe_bare_string?(str)
|
|
148
|
+
|
|
149
|
+
quote_always(str)
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
private
|
|
153
|
+
|
|
154
|
+
def safe_bare_string?(str)
|
|
155
|
+
return false unless str.match?(Lutaml::Lml::Quoting::BARE_WORD)
|
|
156
|
+
return false if str.match?(/\A(?:true|false|null)\z/)
|
|
157
|
+
|
|
158
|
+
!str.match?(/\A\d/)
|
|
159
|
+
end
|
|
160
|
+
end
|
|
161
|
+
end
|
|
162
|
+
end
|
|
163
|
+
end
|
|
164
|
+
end
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "lutaml/lml/format/adapter/document"
|
|
4
|
+
require "lutaml/lml/format/adapter/mapping"
|
|
5
|
+
require "lutaml/lml/format/adapter/transform"
|
|
6
|
+
require "lutaml/lml/format/adapter/standard_adapter"
|
|
7
|
+
|
|
8
|
+
module Lutaml
|
|
9
|
+
module Lml
|
|
10
|
+
module Format
|
|
11
|
+
module Adapter
|
|
12
|
+
autoload :Document, "lutaml/lml/format/adapter/document"
|
|
13
|
+
autoload :Mapping, "lutaml/lml/format/adapter/mapping"
|
|
14
|
+
autoload :Transform, "lutaml/lml/format/adapter/transform"
|
|
15
|
+
autoload :StandardAdapter, "lutaml/lml/format/adapter/standard_adapter"
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
# ExportTransformer is defined at Lutaml::Model::ExportTransformer but
|
|
22
|
+
# referenced as bare ExportTransformer from KeyValue::Transform. Bridge the gap
|
|
23
|
+
# so constant resolution succeeds for the :lml format's to_lml path.
|
|
24
|
+
unless Lutaml::KeyValue.const_defined?(:ExportTransformer)
|
|
25
|
+
Lutaml::KeyValue::ExportTransformer = Lutaml::Model::ExportTransformer
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
Lutaml::Model::FormatRegistry.register(
|
|
29
|
+
:lml,
|
|
30
|
+
mapping_class: Lutaml::Lml::Format::Adapter::Mapping,
|
|
31
|
+
adapter_class: Lutaml::Lml::Format::Adapter::StandardAdapter,
|
|
32
|
+
transformer: Lutaml::Lml::Format::Adapter::Transform,
|
|
33
|
+
key_value: true,
|
|
34
|
+
)
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "lutaml/lml/has_attributes"
|
|
4
|
+
|
|
5
|
+
module Lutaml
|
|
6
|
+
module Formatter
|
|
7
|
+
class << self
|
|
8
|
+
def all
|
|
9
|
+
@all ||= []
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def find_by_name(name)
|
|
13
|
+
name = name.to_sym
|
|
14
|
+
all.detect { |formatter_class| formatter_class.formatter_name == name }
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
class Base
|
|
19
|
+
FORMAT_HANDLERS = {
|
|
20
|
+
Lml::TopElementAttribute => :format_attribute,
|
|
21
|
+
Lml::Operation => :format_operation,
|
|
22
|
+
Lml::Association => :format_relationship,
|
|
23
|
+
Lml::Document => :format_document,
|
|
24
|
+
Lml::DataType => :format_class,
|
|
25
|
+
Lml::UmlClass => :format_class,
|
|
26
|
+
Lml::Enum => :format_class,
|
|
27
|
+
}.freeze
|
|
28
|
+
|
|
29
|
+
class << self
|
|
30
|
+
def inherited(subclass)
|
|
31
|
+
super
|
|
32
|
+
Formatter.all << subclass
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def format(node, attributes = {})
|
|
36
|
+
new(attributes).format(node)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
# Registry key for Formatter.find_by_name. Deliberately not
|
|
40
|
+
# `name` — shadowing Class#name breaks Ruby internals and any
|
|
41
|
+
# library that legitimately calls .name on these classes.
|
|
42
|
+
def formatter_name
|
|
43
|
+
to_s.split("::").last.downcase.to_sym
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
include Lml::HasAttributes
|
|
48
|
+
|
|
49
|
+
def initialize(attributes = {})
|
|
50
|
+
update_attributes(attributes)
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def name
|
|
54
|
+
self.class.formatter_name
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
attr_reader :type
|
|
58
|
+
|
|
59
|
+
def type=(value)
|
|
60
|
+
@type = value.to_s.strip.downcase.to_sym
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def format(node)
|
|
64
|
+
dispatch_format(node)
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def dispatch_format(node)
|
|
68
|
+
handler = FORMAT_HANDLERS.find { |type, _| node.is_a?(type) }&.last
|
|
69
|
+
raise Lml::Error, "no format handler for #{node.class}" unless handler
|
|
70
|
+
|
|
71
|
+
public_send(handler, node)
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def format_attribute(_node) = raise(NotImplementedError)
|
|
75
|
+
def format_operation(_node) = raise(NotImplementedError)
|
|
76
|
+
def format_relationship(_node) = raise(NotImplementedError)
|
|
77
|
+
def format_class(_node) = raise(NotImplementedError)
|
|
78
|
+
def format_document(_node) = raise(NotImplementedError)
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
end
|