lutaml-model 0.7.1 → 0.7.7
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/.envrc +1 -0
- data/.github/workflows/dependent-tests.yml +4 -0
- data/.github/workflows/rake.yml +12 -0
- data/.github/workflows/release.yml +3 -0
- data/.gitignore +6 -1
- data/.irbrc +1 -0
- data/.pryrc +1 -0
- data/.rubocop.yml +1 -1
- data/.rubocop_todo.yml +58 -84
- data/Gemfile +4 -1
- data/README.adoc +3115 -365
- data/RELEASE_NOTES.adoc +346 -0
- data/docs/custom_adapters.adoc +144 -0
- data/docs/custom_registers.adoc +228 -0
- data/docs/schema_generation.adoc +898 -0
- data/docs/schema_import.adoc +364 -0
- data/flake.lock +114 -0
- data/flake.nix +103 -0
- data/lib/lutaml/model/attribute.rb +242 -100
- data/lib/lutaml/model/choice.rb +30 -0
- data/lib/lutaml/model/collection.rb +212 -0
- data/lib/lutaml/model/comparable_model.rb +3 -3
- data/lib/lutaml/model/config.rb +71 -42
- data/lib/lutaml/model/constants.rb +2 -0
- data/lib/lutaml/model/error/element_count_out_of_range_error.rb +29 -0
- data/lib/lutaml/model/error/invalid_attribute_name_error.rb +15 -0
- data/lib/lutaml/model/error/invalid_attribute_options_error.rb +16 -0
- data/lib/lutaml/model/error/invalid_choice_range_error.rb +3 -5
- data/lib/lutaml/model/error/polymorphic_error.rb +7 -2
- data/lib/lutaml/model/error/register/not_registrable_class_error.rb +11 -0
- data/lib/lutaml/model/error/type/invalid_value_error.rb +5 -3
- data/lib/lutaml/model/error/type/max_bound_error.rb +20 -0
- data/lib/lutaml/model/error/type/max_length_error.rb +20 -0
- data/lib/lutaml/model/error/type/min_bound_error.rb +20 -0
- data/lib/lutaml/model/error/type/min_length_error.rb +20 -0
- data/lib/lutaml/model/error/type/pattern_not_matched_error.rb +18 -0
- data/lib/lutaml/model/error/validation_failed_error.rb +9 -0
- data/lib/lutaml/model/error.rb +10 -0
- data/lib/lutaml/model/errors.rb +36 -0
- data/lib/lutaml/model/format_registry.rb +44 -0
- data/lib/lutaml/model/global_register.rb +41 -0
- data/lib/lutaml/model/hash_adapter/document.rb +11 -0
- data/lib/lutaml/model/hash_adapter/mapping.rb +19 -0
- data/lib/lutaml/model/hash_adapter/mapping_rule.rb +9 -0
- data/lib/lutaml/model/hash_adapter/standard_adapter.rb +17 -0
- data/lib/lutaml/model/hash_adapter/transform.rb +8 -0
- data/lib/lutaml/model/hash_adapter.rb +21 -0
- data/lib/lutaml/model/json/document.rb +11 -0
- data/lib/lutaml/model/json/mapping.rb +19 -0
- data/lib/lutaml/model/json/mapping_rule.rb +9 -0
- data/lib/lutaml/model/{json_adapter → json}/multi_json_adapter.rb +4 -5
- data/lib/lutaml/model/{json_adapter/standard_json_adapter.rb → json/standard_adapter.rb} +5 -3
- data/lib/lutaml/model/json/transform.rb +8 -0
- data/lib/lutaml/model/json.rb +21 -0
- data/lib/lutaml/model/jsonl/document.rb +14 -0
- data/lib/lutaml/model/jsonl/mapping.rb +19 -0
- data/lib/lutaml/model/jsonl/mapping_rule.rb +9 -0
- data/lib/lutaml/model/jsonl/standard_adapter.rb +33 -0
- data/lib/lutaml/model/jsonl/transform.rb +19 -0
- data/lib/lutaml/model/jsonl.rb +21 -0
- data/lib/lutaml/model/key_value_document.rb +28 -0
- data/lib/lutaml/model/mapping/key_value_mapping.rb +85 -13
- data/lib/lutaml/model/mapping/key_value_mapping_rule.rb +5 -0
- data/lib/lutaml/model/mapping/mapping.rb +13 -0
- data/lib/lutaml/model/mapping/mapping_rule.rb +15 -9
- data/lib/lutaml/model/register.rb +105 -0
- data/lib/lutaml/model/{toml_adapter.rb → registrable.rb} +1 -1
- data/lib/lutaml/model/schema/base_schema.rb +64 -0
- data/lib/lutaml/model/schema/decorators/attribute.rb +114 -0
- data/lib/lutaml/model/schema/decorators/choices.rb +31 -0
- data/lib/lutaml/model/schema/decorators/class_definition.rb +85 -0
- data/lib/lutaml/model/schema/decorators/definition_collection.rb +97 -0
- data/lib/lutaml/model/schema/generator/definition.rb +53 -0
- data/lib/lutaml/model/schema/generator/definitions_collection.rb +81 -0
- data/lib/lutaml/model/schema/generator/properties_collection.rb +63 -0
- data/lib/lutaml/model/schema/generator/property.rb +110 -0
- data/lib/lutaml/model/schema/generator/ref.rb +24 -0
- data/lib/lutaml/model/schema/helpers/template_helper.rb +49 -0
- data/lib/lutaml/model/schema/json_schema.rb +42 -49
- data/lib/lutaml/model/schema/relaxng_schema.rb +14 -10
- data/lib/lutaml/model/schema/renderer.rb +36 -0
- data/lib/lutaml/model/schema/shared_methods.rb +24 -0
- data/lib/lutaml/model/schema/templates/model.erb +9 -0
- data/lib/lutaml/model/schema/xml_compiler/attribute.rb +85 -0
- data/lib/lutaml/model/schema/xml_compiler/attribute_group.rb +45 -0
- data/lib/lutaml/model/schema/xml_compiler/choice.rb +65 -0
- data/lib/lutaml/model/schema/xml_compiler/complex_content.rb +27 -0
- data/lib/lutaml/model/schema/xml_compiler/complex_content_restriction.rb +34 -0
- data/lib/lutaml/model/schema/xml_compiler/complex_type.rb +136 -0
- data/lib/lutaml/model/schema/xml_compiler/element.rb +104 -0
- data/lib/lutaml/model/schema/xml_compiler/group.rb +97 -0
- data/lib/lutaml/model/schema/xml_compiler/restriction.rb +101 -0
- data/lib/lutaml/model/schema/xml_compiler/sequence.rb +50 -0
- data/lib/lutaml/model/schema/xml_compiler/simple_content.rb +36 -0
- data/lib/lutaml/model/schema/xml_compiler/simple_type.rb +189 -0
- data/lib/lutaml/model/schema/xml_compiler.rb +231 -587
- data/lib/lutaml/model/schema/xsd_schema.rb +12 -8
- data/lib/lutaml/model/schema/yaml_schema.rb +41 -35
- data/lib/lutaml/model/schema.rb +1 -0
- data/lib/lutaml/model/sequence.rb +60 -30
- data/lib/lutaml/model/serialization_adapter.rb +22 -0
- data/lib/lutaml/model/serialize.rb +296 -548
- data/lib/lutaml/model/services/base.rb +11 -0
- data/lib/lutaml/model/services/logger.rb +54 -0
- data/lib/lutaml/model/services/rule_value_extractor.rb +92 -0
- data/lib/lutaml/model/services/transformer.rb +48 -0
- data/lib/lutaml/model/services/type/validator/number.rb +25 -0
- data/lib/lutaml/model/services/type/validator/string.rb +52 -0
- data/lib/lutaml/model/services/type/validator.rb +43 -0
- data/lib/lutaml/model/services/validator.rb +145 -0
- data/lib/lutaml/model/services.rb +5 -0
- data/lib/lutaml/model/toml/document.rb +11 -0
- data/lib/lutaml/model/toml/mapping.rb +27 -0
- data/lib/lutaml/model/toml/mapping_rule.rb +9 -0
- data/lib/lutaml/model/{toml_adapter → toml}/toml_rb_adapter.rb +3 -3
- data/lib/lutaml/model/toml/tomlib_adapter.rb +19 -0
- data/lib/lutaml/model/toml/transform.rb +8 -0
- data/lib/lutaml/model/toml.rb +30 -0
- data/lib/lutaml/model/transform/key_value_transform.rb +297 -0
- data/lib/lutaml/model/transform/xml_transform.rb +228 -0
- data/lib/lutaml/model/transform.rb +93 -0
- data/lib/lutaml/model/type/boolean.rb +1 -1
- data/lib/lutaml/model/type/date.rb +1 -1
- data/lib/lutaml/model/type/date_time.rb +1 -1
- data/lib/lutaml/model/type/decimal.rb +11 -9
- data/lib/lutaml/model/type/float.rb +2 -1
- data/lib/lutaml/model/type/integer.rb +24 -21
- data/lib/lutaml/model/type/string.rb +4 -2
- data/lib/lutaml/model/type/time.rb +1 -1
- data/lib/lutaml/model/type/time_without_date.rb +1 -1
- data/lib/lutaml/model/type/value.rb +11 -10
- data/lib/lutaml/model/type.rb +5 -2
- data/lib/lutaml/model/uninitialized_class.rb +1 -1
- data/lib/lutaml/model/utils.rb +56 -4
- data/lib/lutaml/model/validation.rb +6 -4
- data/lib/lutaml/model/version.rb +1 -1
- data/lib/lutaml/model/{xml_adapter → xml}/builder/nokogiri.rb +2 -2
- data/lib/lutaml/model/{xml_adapter → xml}/builder/oga.rb +10 -10
- data/lib/lutaml/model/{xml_adapter → xml}/builder/ox.rb +1 -1
- data/lib/lutaml/model/{xml_adapter/xml_document.rb → xml/document.rb} +42 -25
- data/lib/lutaml/model/xml/element.rb +32 -0
- data/lib/lutaml/model/xml/mapping.rb +471 -0
- data/lib/lutaml/model/xml/mapping_rule.rb +149 -0
- data/lib/lutaml/model/xml/nokogiri_adapter.rb +234 -0
- data/lib/lutaml/model/{xml_adapter → xml}/oga/document.rb +1 -1
- data/lib/lutaml/model/{xml_adapter → xml}/oga/element.rb +7 -2
- data/lib/lutaml/model/xml/oga_adapter.rb +172 -0
- data/lib/lutaml/model/xml/ox_adapter.rb +229 -0
- data/lib/lutaml/model/xml/transform.rb +8 -0
- data/lib/lutaml/model/{xml_adapter → xml}/xml_attribute.rb +1 -1
- data/lib/lutaml/model/{xml_adapter → xml}/xml_element.rb +9 -31
- data/lib/lutaml/model/{xml_adapter → xml}/xml_namespace.rb +1 -1
- data/lib/lutaml/model/xml.rb +31 -0
- data/lib/lutaml/model/xml_adapter/element.rb +11 -25
- data/lib/lutaml/model/xml_adapter/nokogiri_adapter.rb +6 -223
- data/lib/lutaml/model/xml_adapter/oga_adapter.rb +13 -163
- data/lib/lutaml/model/xml_adapter/ox_adapter.rb +10 -207
- data/lib/lutaml/model/yaml/document.rb +10 -0
- data/lib/lutaml/model/yaml/mapping.rb +19 -0
- data/lib/lutaml/model/yaml/mapping_rule.rb +9 -0
- data/lib/lutaml/model/{yaml_adapter/standard_yaml_adapter.rb → yaml/standard_adapter.rb} +4 -3
- data/lib/lutaml/model/yaml/transform.rb +8 -0
- data/lib/lutaml/model/yaml.rb +21 -0
- data/lib/lutaml/model/yamls/document.rb +14 -0
- data/lib/lutaml/model/yamls/mapping.rb +19 -0
- data/lib/lutaml/model/yamls/mapping_rule.rb +9 -0
- data/lib/lutaml/model/yamls/standard_adapter.rb +34 -0
- data/lib/lutaml/model/yamls/transform.rb +19 -0
- data/lib/lutaml/model/yamls.rb +21 -0
- data/lib/lutaml/model.rb +15 -4
- data/lutaml-model.gemspec +0 -4
- data/spec/benchmarks/xml_parsing_benchmark_spec.rb +5 -6
- data/spec/fixtures/xml/advanced_test_schema.xsd +134 -0
- data/spec/fixtures/xml/examples/nested_categories.xml +55 -0
- data/spec/fixtures/xml/examples/valid_catalog.xml +43 -0
- data/spec/fixtures/xml/product_catalog.xsd +151 -0
- data/spec/fixtures/xml/specifications_schema.xsd +38 -0
- data/spec/lutaml/model/attribute_collection_spec.rb +101 -0
- data/spec/lutaml/model/attribute_spec.rb +41 -44
- data/spec/lutaml/model/cdata_spec.rb +7 -7
- data/spec/lutaml/model/choice_spec.rb +44 -0
- data/spec/lutaml/model/custom_bibtex_adapter_spec.rb +598 -0
- data/spec/lutaml/model/custom_collection_spec.rb +830 -0
- data/spec/lutaml/model/custom_vobject_adapter_spec.rb +1226 -0
- data/spec/lutaml/model/global_register_spec.rb +108 -0
- data/spec/lutaml/model/group_spec.rb +27 -10
- data/spec/lutaml/model/hash/adapter_spec.rb +255 -0
- data/spec/lutaml/model/json_adapter_spec.rb +6 -6
- data/spec/lutaml/model/jsonl/standard_adapter_spec.rb +91 -0
- data/spec/lutaml/model/jsonl_spec.rb +229 -0
- data/spec/lutaml/model/key_value_mapping_spec.rb +25 -1
- data/spec/lutaml/model/mixed_content_spec.rb +24 -24
- data/spec/lutaml/model/multiple_mapping_spec.rb +6 -6
- data/spec/lutaml/model/ordered_content_spec.rb +6 -6
- data/spec/lutaml/model/polymorphic_spec.rb +178 -0
- data/spec/lutaml/model/register/key_value_spec.rb +275 -0
- data/spec/lutaml/model/register/xml_spec.rb +185 -0
- data/spec/lutaml/model/register_spec.rb +147 -0
- data/spec/lutaml/model/root_mappings_spec.rb +3 -3
- data/spec/lutaml/model/rule_value_extractor_spec.rb +162 -0
- data/spec/lutaml/model/schema/generator/definitions_collection_spec.rb +120 -0
- data/spec/lutaml/model/schema/json_schema_spec.rb +412 -51
- data/spec/lutaml/model/schema/json_schema_to_models_spec.rb +383 -0
- data/spec/lutaml/model/schema/xml_compiler/attribute_group_spec.rb +65 -0
- data/spec/lutaml/model/schema/xml_compiler/attribute_spec.rb +63 -0
- data/spec/lutaml/model/schema/xml_compiler/choice_spec.rb +71 -0
- data/spec/lutaml/model/schema/xml_compiler/complex_content_restriction_spec.rb +55 -0
- data/spec/lutaml/model/schema/xml_compiler/complex_content_spec.rb +37 -0
- data/spec/lutaml/model/schema/xml_compiler/complex_type_spec.rb +173 -0
- data/spec/lutaml/model/schema/xml_compiler/element_spec.rb +63 -0
- data/spec/lutaml/model/schema/xml_compiler/group_spec.rb +86 -0
- data/spec/lutaml/model/schema/xml_compiler/restriction_spec.rb +76 -0
- data/spec/lutaml/model/schema/xml_compiler/sequence_spec.rb +59 -0
- data/spec/lutaml/model/schema/xml_compiler/simple_content_spec.rb +55 -0
- data/spec/lutaml/model/schema/xml_compiler/simple_type_spec.rb +181 -0
- data/spec/lutaml/model/schema/xml_compiler_spec.rb +503 -1804
- data/spec/lutaml/model/schema/yaml_schema_spec.rb +249 -26
- data/spec/lutaml/model/sequence_spec.rb +36 -0
- data/spec/lutaml/model/serializable_spec.rb +201 -94
- data/spec/lutaml/model/toml_adapter_spec.rb +6 -6
- data/spec/lutaml/model/toml_spec.rb +51 -0
- data/spec/lutaml/model/transformation_spec.rb +72 -15
- data/spec/lutaml/model/type_spec.rb +8 -4
- data/spec/lutaml/model/uninitialized_class_spec.rb +96 -0
- data/spec/lutaml/model/utils_spec.rb +3 -3
- data/spec/lutaml/model/xml/derived_attributes_spec.rb +1 -1
- data/spec/lutaml/model/xml/namespace_spec.rb +57 -0
- data/spec/lutaml/model/xml/root_mappings/nested_child_mappings_spec.rb +217 -0
- data/spec/lutaml/model/xml/xml_element_spec.rb +7 -1
- data/spec/lutaml/model/xml_adapter/nokogiri_adapter_spec.rb +2 -2
- data/spec/lutaml/model/xml_adapter/oga_adapter_spec.rb +2 -2
- data/spec/lutaml/model/xml_adapter/ox_adapter_spec.rb +2 -2
- data/spec/lutaml/model/xml_adapter/xml_namespace_spec.rb +12 -12
- data/spec/lutaml/model/xml_adapter_spec.rb +30 -6
- data/spec/lutaml/model/xml_mapping_rule_spec.rb +14 -7
- data/spec/lutaml/model/xml_mapping_spec.rb +27 -15
- data/spec/lutaml/model/xml_spec.rb +63 -0
- data/spec/lutaml/model/yaml_adapter_spec.rb +3 -5
- data/spec/lutaml/model/yamls/standard_adapter_spec.rb +183 -0
- data/spec/lutaml/model/yamls_spec.rb +294 -0
- data/spec/spec_helper.rb +4 -3
- metadata +162 -60
- data/lib/lutaml/model/json_adapter/json_document.rb +0 -20
- data/lib/lutaml/model/json_adapter/json_object.rb +0 -28
- data/lib/lutaml/model/loggable.rb +0 -15
- data/lib/lutaml/model/mapping/json_mapping.rb +0 -17
- data/lib/lutaml/model/mapping/toml_mapping.rb +0 -25
- data/lib/lutaml/model/mapping/xml_mapping.rb +0 -389
- data/lib/lutaml/model/mapping/xml_mapping_rule.rb +0 -139
- data/lib/lutaml/model/mapping/yaml_mapping.rb +0 -17
- data/lib/lutaml/model/mapping.rb +0 -14
- data/lib/lutaml/model/schema/templates/simple_type.rb +0 -247
- data/lib/lutaml/model/toml_adapter/toml_document.rb +0 -20
- data/lib/lutaml/model/toml_adapter/toml_object.rb +0 -28
- data/lib/lutaml/model/toml_adapter/tomlib_adapter.rb +0 -20
- data/lib/lutaml/model/yaml_adapter/yaml_document.rb +0 -20
- data/lib/lutaml/model/yaml_adapter/yaml_object.rb +0 -28
- data/lib/lutaml/model/yaml_adapter.rb +0 -8
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require_relative "json_object"
|
|
4
|
-
|
|
5
|
-
module Lutaml
|
|
6
|
-
module Model
|
|
7
|
-
module JsonAdapter
|
|
8
|
-
# Base class for JSON documents
|
|
9
|
-
class JsonDocument < JsonObject
|
|
10
|
-
def self.parse(json, _options = {})
|
|
11
|
-
raise NotImplementedError, "Subclasses must implement `parse`."
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
def to_json(*args)
|
|
15
|
-
raise NotImplementedError, "Subclasses must implement `to_json`."
|
|
16
|
-
end
|
|
17
|
-
end
|
|
18
|
-
end
|
|
19
|
-
end
|
|
20
|
-
end
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Lutaml
|
|
4
|
-
module Model
|
|
5
|
-
module JsonAdapter
|
|
6
|
-
# Base class for JSON objects
|
|
7
|
-
class JsonObject
|
|
8
|
-
attr_reader :attributes
|
|
9
|
-
|
|
10
|
-
def initialize(attributes = {})
|
|
11
|
-
@attributes = attributes
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
def [](key)
|
|
15
|
-
@attributes[key]
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
def []=(key, value)
|
|
19
|
-
@attributes[key] = value
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
def to_h
|
|
23
|
-
@attributes
|
|
24
|
-
end
|
|
25
|
-
end
|
|
26
|
-
end
|
|
27
|
-
end
|
|
28
|
-
end
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
module Lutaml
|
|
2
|
-
module Model
|
|
3
|
-
module Loggable
|
|
4
|
-
def self.included(base)
|
|
5
|
-
base.define_method :warn_auto_handling do |name|
|
|
6
|
-
caller_file = File.basename(caller_locations(2, 1)[0].path)
|
|
7
|
-
caller_line = caller_locations(2, 1)[0].lineno
|
|
8
|
-
|
|
9
|
-
str = "[Lutaml::Model] WARN: `#{name}` is handled by default. No need to explecitly define at `#{caller_file}:#{caller_line}`"
|
|
10
|
-
warn(str)
|
|
11
|
-
end
|
|
12
|
-
end
|
|
13
|
-
end
|
|
14
|
-
end
|
|
15
|
-
end
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
require_relative "key_value_mapping"
|
|
2
|
-
|
|
3
|
-
module Lutaml
|
|
4
|
-
module Model
|
|
5
|
-
class JsonMapping < KeyValueMapping
|
|
6
|
-
def initialize
|
|
7
|
-
super(:json)
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
def deep_dup
|
|
11
|
-
self.class.new.tap do |new_mapping|
|
|
12
|
-
new_mapping.instance_variable_set(:@mappings, duplicate_mappings)
|
|
13
|
-
end
|
|
14
|
-
end
|
|
15
|
-
end
|
|
16
|
-
end
|
|
17
|
-
end
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
require_relative "key_value_mapping"
|
|
2
|
-
|
|
3
|
-
module Lutaml
|
|
4
|
-
module Model
|
|
5
|
-
class TomlMapping < KeyValueMapping
|
|
6
|
-
def initialize
|
|
7
|
-
super(:toml)
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
def deep_dup
|
|
11
|
-
self.class.new.tap do |new_mapping|
|
|
12
|
-
new_mapping.instance_variable_set(:@mappings, duplicate_mappings)
|
|
13
|
-
end
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
def validate!(key, to, with, render_nil, render_empty)
|
|
17
|
-
super
|
|
18
|
-
|
|
19
|
-
if [true, :as_nil].include?(render_nil) || render_empty == :as_nil
|
|
20
|
-
raise IncorrectMappingArgumentsError, "nil values are not supported in toml format"
|
|
21
|
-
end
|
|
22
|
-
end
|
|
23
|
-
end
|
|
24
|
-
end
|
|
25
|
-
end
|
|
@@ -1,389 +0,0 @@
|
|
|
1
|
-
require_relative "xml_mapping_rule"
|
|
2
|
-
|
|
3
|
-
module Lutaml
|
|
4
|
-
module Model
|
|
5
|
-
class XmlMapping
|
|
6
|
-
include Lutaml::Model::Loggable
|
|
7
|
-
|
|
8
|
-
TYPES = {
|
|
9
|
-
attribute: :map_attribute,
|
|
10
|
-
element: :map_element,
|
|
11
|
-
content: :map_content,
|
|
12
|
-
all_content: :map_all,
|
|
13
|
-
}.freeze
|
|
14
|
-
|
|
15
|
-
attr_reader :root_element,
|
|
16
|
-
:namespace_uri,
|
|
17
|
-
:namespace_prefix,
|
|
18
|
-
:mixed_content,
|
|
19
|
-
:ordered,
|
|
20
|
-
:element_sequence
|
|
21
|
-
|
|
22
|
-
def initialize
|
|
23
|
-
@elements = {}
|
|
24
|
-
@attributes = {}
|
|
25
|
-
@element_sequence = []
|
|
26
|
-
@content_mapping = nil
|
|
27
|
-
@raw_mapping = nil
|
|
28
|
-
@mixed_content = false
|
|
29
|
-
@format = :xml
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
alias mixed_content? mixed_content
|
|
33
|
-
alias ordered? ordered
|
|
34
|
-
|
|
35
|
-
def root(name, mixed: false, ordered: false)
|
|
36
|
-
@root_element = name
|
|
37
|
-
@mixed_content = mixed
|
|
38
|
-
@ordered = ordered || mixed # mixed contenet will always be ordered
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
def root?
|
|
42
|
-
!!root_element
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
def no_root
|
|
46
|
-
@no_root = true
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
def no_root?
|
|
50
|
-
!!@no_root
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
def prefixed_root
|
|
54
|
-
if namespace_uri && namespace_prefix
|
|
55
|
-
"#{namespace_prefix}:#{root_element}"
|
|
56
|
-
else
|
|
57
|
-
root_element
|
|
58
|
-
end
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
def namespace(uri, prefix = nil)
|
|
62
|
-
raise Lutaml::Model::NoRootNamespaceError if no_root?
|
|
63
|
-
|
|
64
|
-
@namespace_uri = uri
|
|
65
|
-
@namespace_prefix = prefix
|
|
66
|
-
end
|
|
67
|
-
|
|
68
|
-
# rubocop:disable Metrics/ParameterLists
|
|
69
|
-
def map_element(
|
|
70
|
-
name,
|
|
71
|
-
to: nil,
|
|
72
|
-
render_nil: false,
|
|
73
|
-
render_default: false,
|
|
74
|
-
render_empty: false,
|
|
75
|
-
treat_nil: :nil,
|
|
76
|
-
treat_empty: :empty,
|
|
77
|
-
treat_omitted: :nil,
|
|
78
|
-
with: {},
|
|
79
|
-
delegate: nil,
|
|
80
|
-
cdata: false,
|
|
81
|
-
polymorphic: {},
|
|
82
|
-
namespace: (namespace_set = false
|
|
83
|
-
nil),
|
|
84
|
-
prefix: (prefix_set = false
|
|
85
|
-
nil),
|
|
86
|
-
transform: {},
|
|
87
|
-
value_map: {}
|
|
88
|
-
)
|
|
89
|
-
validate!(
|
|
90
|
-
name, to, with, render_nil, render_empty, type: TYPES[:element]
|
|
91
|
-
)
|
|
92
|
-
|
|
93
|
-
rule = XmlMappingRule.new(
|
|
94
|
-
name,
|
|
95
|
-
to: to,
|
|
96
|
-
render_nil: render_nil,
|
|
97
|
-
render_default: render_default,
|
|
98
|
-
render_empty: render_empty,
|
|
99
|
-
treat_nil: treat_nil,
|
|
100
|
-
treat_empty: treat_empty,
|
|
101
|
-
treat_omitted: treat_omitted,
|
|
102
|
-
with: with,
|
|
103
|
-
delegate: delegate,
|
|
104
|
-
cdata: cdata,
|
|
105
|
-
namespace: namespace,
|
|
106
|
-
default_namespace: namespace_uri,
|
|
107
|
-
prefix: prefix,
|
|
108
|
-
polymorphic: polymorphic,
|
|
109
|
-
namespace_set: namespace_set != false,
|
|
110
|
-
prefix_set: prefix_set != false,
|
|
111
|
-
transform: transform,
|
|
112
|
-
value_map: value_map,
|
|
113
|
-
)
|
|
114
|
-
@elements[rule.namespaced_name] = rule
|
|
115
|
-
end
|
|
116
|
-
|
|
117
|
-
def map_attribute(
|
|
118
|
-
name,
|
|
119
|
-
to: nil,
|
|
120
|
-
render_nil: false,
|
|
121
|
-
render_default: false,
|
|
122
|
-
render_empty: false,
|
|
123
|
-
with: {},
|
|
124
|
-
delegate: nil,
|
|
125
|
-
polymorphic_map: {},
|
|
126
|
-
namespace: (namespace_set = false
|
|
127
|
-
nil),
|
|
128
|
-
prefix: (prefix_set = false
|
|
129
|
-
nil),
|
|
130
|
-
value_map: {}
|
|
131
|
-
)
|
|
132
|
-
validate!(
|
|
133
|
-
name, to, with, render_nil, render_empty, type: TYPES[:attribute]
|
|
134
|
-
)
|
|
135
|
-
|
|
136
|
-
warn_auto_handling(name) if name == "schemaLocation"
|
|
137
|
-
|
|
138
|
-
rule = XmlMappingRule.new(
|
|
139
|
-
name,
|
|
140
|
-
to: to,
|
|
141
|
-
render_nil: render_nil,
|
|
142
|
-
render_default: render_default,
|
|
143
|
-
with: with,
|
|
144
|
-
delegate: delegate,
|
|
145
|
-
namespace: namespace,
|
|
146
|
-
prefix: prefix,
|
|
147
|
-
attribute: true,
|
|
148
|
-
polymorphic_map: polymorphic_map,
|
|
149
|
-
default_namespace: namespace_uri,
|
|
150
|
-
namespace_set: namespace_set != false,
|
|
151
|
-
prefix_set: prefix_set != false,
|
|
152
|
-
value_map: value_map,
|
|
153
|
-
)
|
|
154
|
-
@attributes[rule.namespaced_name] = rule
|
|
155
|
-
end
|
|
156
|
-
|
|
157
|
-
# rubocop:enable Metrics/ParameterLists
|
|
158
|
-
|
|
159
|
-
def map_content(
|
|
160
|
-
to: nil,
|
|
161
|
-
render_nil: false,
|
|
162
|
-
render_default: false,
|
|
163
|
-
render_empty: false,
|
|
164
|
-
with: {},
|
|
165
|
-
delegate: nil,
|
|
166
|
-
mixed: false,
|
|
167
|
-
cdata: false,
|
|
168
|
-
value_map: {}
|
|
169
|
-
)
|
|
170
|
-
validate!(
|
|
171
|
-
"content", to, with, render_nil, render_empty, type: TYPES[:content]
|
|
172
|
-
)
|
|
173
|
-
|
|
174
|
-
@content_mapping = XmlMappingRule.new(
|
|
175
|
-
nil,
|
|
176
|
-
to: to,
|
|
177
|
-
render_nil: render_nil,
|
|
178
|
-
render_default: render_default,
|
|
179
|
-
render_empty: render_empty,
|
|
180
|
-
with: with,
|
|
181
|
-
delegate: delegate,
|
|
182
|
-
mixed_content: mixed,
|
|
183
|
-
cdata: cdata,
|
|
184
|
-
value_map: value_map,
|
|
185
|
-
)
|
|
186
|
-
end
|
|
187
|
-
|
|
188
|
-
def map_all(
|
|
189
|
-
to:,
|
|
190
|
-
render_nil: false,
|
|
191
|
-
render_default: false,
|
|
192
|
-
delegate: nil,
|
|
193
|
-
with: {},
|
|
194
|
-
namespace: (namespace_set = false
|
|
195
|
-
nil),
|
|
196
|
-
prefix: (prefix_set = false
|
|
197
|
-
nil),
|
|
198
|
-
render_empty: false
|
|
199
|
-
)
|
|
200
|
-
validate!(
|
|
201
|
-
Constants::RAW_MAPPING_KEY,
|
|
202
|
-
to,
|
|
203
|
-
with,
|
|
204
|
-
render_nil,
|
|
205
|
-
render_empty,
|
|
206
|
-
type: TYPES[:all_content],
|
|
207
|
-
)
|
|
208
|
-
|
|
209
|
-
rule = XmlMappingRule.new(
|
|
210
|
-
Constants::RAW_MAPPING_KEY,
|
|
211
|
-
to: to,
|
|
212
|
-
render_nil: render_nil,
|
|
213
|
-
render_default: render_default,
|
|
214
|
-
with: with,
|
|
215
|
-
delegate: delegate,
|
|
216
|
-
namespace: namespace,
|
|
217
|
-
prefix: prefix,
|
|
218
|
-
default_namespace: namespace_uri,
|
|
219
|
-
namespace_set: namespace_set != false,
|
|
220
|
-
prefix_set: prefix_set != false,
|
|
221
|
-
)
|
|
222
|
-
|
|
223
|
-
@raw_mapping = rule
|
|
224
|
-
end
|
|
225
|
-
|
|
226
|
-
alias map_all_content map_all
|
|
227
|
-
|
|
228
|
-
def sequence(&block)
|
|
229
|
-
@element_sequence << Sequence.new(self).tap do |s|
|
|
230
|
-
s.instance_eval(&block)
|
|
231
|
-
end
|
|
232
|
-
end
|
|
233
|
-
|
|
234
|
-
def import_model_mappings(model)
|
|
235
|
-
raise Lutaml::Model::ImportModelWithRootError.new(model) if model.root?
|
|
236
|
-
|
|
237
|
-
mappings = model.mappings_for(:xml)
|
|
238
|
-
@elements.merge!(mappings.instance_variable_get(:@elements))
|
|
239
|
-
@attributes.merge!(mappings.instance_variable_get(:@attributes))
|
|
240
|
-
(@element_sequence << mappings.element_sequence).flatten!
|
|
241
|
-
end
|
|
242
|
-
|
|
243
|
-
def validate!(key, to, with, render_nil, render_empty, type: nil)
|
|
244
|
-
validate_raw_mappings!(type)
|
|
245
|
-
validate_to_and_with_arguments!(key, to, with)
|
|
246
|
-
|
|
247
|
-
if render_nil == :as_empty || render_empty == :as_empty
|
|
248
|
-
raise IncorrectMappingArgumentsError.new(
|
|
249
|
-
":as_empty is not supported for XML mappings",
|
|
250
|
-
)
|
|
251
|
-
end
|
|
252
|
-
end
|
|
253
|
-
|
|
254
|
-
def validate_to_and_with_arguments!(key, to, with)
|
|
255
|
-
if to.nil? && with.empty?
|
|
256
|
-
raise IncorrectMappingArgumentsError.new(
|
|
257
|
-
":to or :with argument is required for mapping '#{key}'",
|
|
258
|
-
)
|
|
259
|
-
end
|
|
260
|
-
|
|
261
|
-
validate_with_options!(key, with)
|
|
262
|
-
end
|
|
263
|
-
|
|
264
|
-
def validate_with_options!(key, with)
|
|
265
|
-
if !with.empty? && (with[:from].nil? || with[:to].nil?)
|
|
266
|
-
raise IncorrectMappingArgumentsError.new(
|
|
267
|
-
":with argument for mapping '#{key}' requires :to and :from keys",
|
|
268
|
-
)
|
|
269
|
-
end
|
|
270
|
-
end
|
|
271
|
-
|
|
272
|
-
def validate_raw_mappings!(type)
|
|
273
|
-
if !@raw_mapping.nil? && type != TYPES[:attribute]
|
|
274
|
-
raise StandardError, "#{type} is not allowed, only #{TYPES[:attribute]} " \
|
|
275
|
-
"is allowed with #{TYPES[:all_content]}"
|
|
276
|
-
end
|
|
277
|
-
|
|
278
|
-
if !(elements.empty? && content_mapping.nil?) && type == TYPES[:all_content]
|
|
279
|
-
raise StandardError, "#{TYPES[:all_content]} is not allowed with other mappings"
|
|
280
|
-
end
|
|
281
|
-
end
|
|
282
|
-
|
|
283
|
-
def elements
|
|
284
|
-
@elements.values
|
|
285
|
-
end
|
|
286
|
-
|
|
287
|
-
def attributes
|
|
288
|
-
@attributes.values
|
|
289
|
-
end
|
|
290
|
-
|
|
291
|
-
def content_mapping
|
|
292
|
-
@content_mapping
|
|
293
|
-
end
|
|
294
|
-
|
|
295
|
-
def raw_mapping
|
|
296
|
-
@raw_mapping
|
|
297
|
-
end
|
|
298
|
-
|
|
299
|
-
def mappings
|
|
300
|
-
elements + attributes + [content_mapping, raw_mapping].compact
|
|
301
|
-
end
|
|
302
|
-
|
|
303
|
-
def element(name)
|
|
304
|
-
elements.detect do |rule|
|
|
305
|
-
name == rule.to
|
|
306
|
-
end
|
|
307
|
-
end
|
|
308
|
-
|
|
309
|
-
def attribute(name)
|
|
310
|
-
attributes.detect do |rule|
|
|
311
|
-
name == rule.to
|
|
312
|
-
end
|
|
313
|
-
end
|
|
314
|
-
|
|
315
|
-
def find_by_name(name)
|
|
316
|
-
if ["text", "#cdata-section"].include?(name.to_s)
|
|
317
|
-
content_mapping
|
|
318
|
-
else
|
|
319
|
-
mappings.detect do |rule|
|
|
320
|
-
rule.name == name.to_s || rule.name == name.to_sym
|
|
321
|
-
end
|
|
322
|
-
end
|
|
323
|
-
end
|
|
324
|
-
|
|
325
|
-
def mapping_attributes_hash
|
|
326
|
-
@attributes
|
|
327
|
-
end
|
|
328
|
-
|
|
329
|
-
def mapping_elements_hash
|
|
330
|
-
@elements
|
|
331
|
-
end
|
|
332
|
-
|
|
333
|
-
def merge_mapping_attributes(mapping)
|
|
334
|
-
mapping_attributes_hash.merge!(mapping.mapping_attributes_hash)
|
|
335
|
-
end
|
|
336
|
-
|
|
337
|
-
def merge_mapping_elements(mapping)
|
|
338
|
-
mapping_elements_hash.merge!(mapping.mapping_elements_hash)
|
|
339
|
-
end
|
|
340
|
-
|
|
341
|
-
def merge_elements_sequence(mapping)
|
|
342
|
-
mapping.element_sequence.each do |sequence|
|
|
343
|
-
element_sequence << Lutaml::Model::Sequence.new(self).tap do |instance|
|
|
344
|
-
sequence.attributes.each do |attr|
|
|
345
|
-
instance.attributes << attr.deep_dup
|
|
346
|
-
end
|
|
347
|
-
end
|
|
348
|
-
end
|
|
349
|
-
end
|
|
350
|
-
|
|
351
|
-
def deep_dup
|
|
352
|
-
self.class.new.tap do |xml_mapping|
|
|
353
|
-
xml_mapping.root(@root_element.dup, mixed: @mixed_content,
|
|
354
|
-
ordered: @ordered)
|
|
355
|
-
xml_mapping.namespace(@namespace_uri.dup, @namespace_prefix.dup)
|
|
356
|
-
|
|
357
|
-
attributes_to_dup.each do |var_name|
|
|
358
|
-
value = instance_variable_get(var_name)
|
|
359
|
-
xml_mapping.instance_variable_set(var_name, Utils.deep_dup(value))
|
|
360
|
-
end
|
|
361
|
-
end
|
|
362
|
-
end
|
|
363
|
-
|
|
364
|
-
def polymorphic_mapping
|
|
365
|
-
mappings.find(&:polymorphic_mapping?)
|
|
366
|
-
end
|
|
367
|
-
|
|
368
|
-
def attributes_to_dup
|
|
369
|
-
@attributes_to_dup ||= %i[
|
|
370
|
-
@content_mapping
|
|
371
|
-
@raw_mapping
|
|
372
|
-
@element_sequence
|
|
373
|
-
@attributes
|
|
374
|
-
@elements
|
|
375
|
-
]
|
|
376
|
-
end
|
|
377
|
-
|
|
378
|
-
def dup_mappings(mappings)
|
|
379
|
-
new_mappings = {}
|
|
380
|
-
|
|
381
|
-
mappings.each do |key, mapping_rule|
|
|
382
|
-
new_mappings[key] = mapping_rule.deep_dup
|
|
383
|
-
end
|
|
384
|
-
|
|
385
|
-
new_mappings
|
|
386
|
-
end
|
|
387
|
-
end
|
|
388
|
-
end
|
|
389
|
-
end
|
|
@@ -1,139 +0,0 @@
|
|
|
1
|
-
require_relative "mapping_rule"
|
|
2
|
-
|
|
3
|
-
module Lutaml
|
|
4
|
-
module Model
|
|
5
|
-
class XmlMappingRule < MappingRule
|
|
6
|
-
attr_reader :namespace, :prefix, :mixed_content, :default_namespace, :cdata
|
|
7
|
-
|
|
8
|
-
def initialize(
|
|
9
|
-
name,
|
|
10
|
-
to:,
|
|
11
|
-
render_nil: false,
|
|
12
|
-
render_default: false,
|
|
13
|
-
render_empty: false,
|
|
14
|
-
treat_nil: nil,
|
|
15
|
-
treat_empty: nil,
|
|
16
|
-
treat_omitted: nil,
|
|
17
|
-
with: {},
|
|
18
|
-
delegate: nil,
|
|
19
|
-
namespace: nil,
|
|
20
|
-
prefix: nil,
|
|
21
|
-
mixed_content: false,
|
|
22
|
-
cdata: false,
|
|
23
|
-
namespace_set: false,
|
|
24
|
-
prefix_set: false,
|
|
25
|
-
attribute: false,
|
|
26
|
-
default_namespace: nil,
|
|
27
|
-
polymorphic: {},
|
|
28
|
-
polymorphic_map: {},
|
|
29
|
-
transform: {},
|
|
30
|
-
value_map: {}
|
|
31
|
-
)
|
|
32
|
-
super(
|
|
33
|
-
name,
|
|
34
|
-
to: to,
|
|
35
|
-
render_nil: render_nil,
|
|
36
|
-
render_default: render_default,
|
|
37
|
-
render_empty: render_empty,
|
|
38
|
-
treat_nil: treat_nil,
|
|
39
|
-
treat_empty: treat_empty,
|
|
40
|
-
treat_omitted: treat_omitted,
|
|
41
|
-
with: with,
|
|
42
|
-
delegate: delegate,
|
|
43
|
-
attribute: attribute,
|
|
44
|
-
polymorphic: polymorphic,
|
|
45
|
-
polymorphic_map: polymorphic_map,
|
|
46
|
-
transform: transform,
|
|
47
|
-
value_map: value_map,
|
|
48
|
-
)
|
|
49
|
-
|
|
50
|
-
@namespace = if namespace.to_s == "inherit"
|
|
51
|
-
# we are using inherit_namespace in xml builder by
|
|
52
|
-
# default so no need to do anything here.
|
|
53
|
-
else
|
|
54
|
-
namespace
|
|
55
|
-
end
|
|
56
|
-
@prefix = prefix
|
|
57
|
-
@mixed_content = mixed_content
|
|
58
|
-
@cdata = cdata
|
|
59
|
-
|
|
60
|
-
@default_namespace = default_namespace
|
|
61
|
-
|
|
62
|
-
@namespace_set = namespace_set
|
|
63
|
-
@prefix_set = prefix_set
|
|
64
|
-
end
|
|
65
|
-
|
|
66
|
-
def namespace_set?
|
|
67
|
-
!!@namespace_set
|
|
68
|
-
end
|
|
69
|
-
|
|
70
|
-
def prefix_set?
|
|
71
|
-
!!@prefix_set
|
|
72
|
-
end
|
|
73
|
-
|
|
74
|
-
def content_mapping?
|
|
75
|
-
name.nil?
|
|
76
|
-
end
|
|
77
|
-
|
|
78
|
-
def content_key
|
|
79
|
-
cdata ? "#cdata-section" : "text"
|
|
80
|
-
end
|
|
81
|
-
|
|
82
|
-
def mixed_content?
|
|
83
|
-
!!@mixed_content
|
|
84
|
-
end
|
|
85
|
-
|
|
86
|
-
def prefixed_name
|
|
87
|
-
rule_name = multiple_mappings? ? name.first : name
|
|
88
|
-
if prefix
|
|
89
|
-
"#{prefix}:#{rule_name}"
|
|
90
|
-
else
|
|
91
|
-
rule_name
|
|
92
|
-
end
|
|
93
|
-
end
|
|
94
|
-
|
|
95
|
-
def namespaced_names(parent_namespace = nil)
|
|
96
|
-
if multiple_mappings?
|
|
97
|
-
name.map { |rule_name| namespaced_name(parent_namespace, rule_name) }
|
|
98
|
-
else
|
|
99
|
-
[namespaced_name(parent_namespace)]
|
|
100
|
-
end
|
|
101
|
-
end
|
|
102
|
-
|
|
103
|
-
def namespaced_name(parent_namespace = nil, name = self.name)
|
|
104
|
-
if name.to_s == "lang"
|
|
105
|
-
"#{prefix}:#{name}"
|
|
106
|
-
elsif namespace_set? || @attribute
|
|
107
|
-
[namespace, name].compact.join(":")
|
|
108
|
-
elsif default_namespace
|
|
109
|
-
"#{default_namespace}:#{name}"
|
|
110
|
-
else
|
|
111
|
-
[parent_namespace, name].compact.join(":")
|
|
112
|
-
end
|
|
113
|
-
end
|
|
114
|
-
|
|
115
|
-
def deep_dup
|
|
116
|
-
self.class.new(
|
|
117
|
-
name.dup,
|
|
118
|
-
to: to,
|
|
119
|
-
render_nil: render_nil,
|
|
120
|
-
render_default: render_default,
|
|
121
|
-
with: Utils.deep_dup(custom_methods),
|
|
122
|
-
delegate: delegate,
|
|
123
|
-
namespace: namespace.dup,
|
|
124
|
-
prefix: prefix.dup,
|
|
125
|
-
mixed_content: mixed_content,
|
|
126
|
-
cdata: cdata,
|
|
127
|
-
namespace_set: namespace_set?,
|
|
128
|
-
prefix_set: prefix_set?,
|
|
129
|
-
attribute: attribute,
|
|
130
|
-
polymorphic: polymorphic.dup,
|
|
131
|
-
default_namespace: default_namespace.dup,
|
|
132
|
-
transform: transform.dup,
|
|
133
|
-
render_empty: render_empty.dup,
|
|
134
|
-
value_map: Utils.deep_dup(@value_map),
|
|
135
|
-
)
|
|
136
|
-
end
|
|
137
|
-
end
|
|
138
|
-
end
|
|
139
|
-
end
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
require_relative "key_value_mapping"
|
|
2
|
-
|
|
3
|
-
module Lutaml
|
|
4
|
-
module Model
|
|
5
|
-
class YamlMapping < KeyValueMapping
|
|
6
|
-
def initialize
|
|
7
|
-
super(:yaml)
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
def deep_dup
|
|
11
|
-
self.class.new.tap do |new_mapping|
|
|
12
|
-
new_mapping.instance_variable_set(:@mappings, duplicate_mappings)
|
|
13
|
-
end
|
|
14
|
-
end
|
|
15
|
-
end
|
|
16
|
-
end
|
|
17
|
-
end
|
data/lib/lutaml/model/mapping.rb
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
module Lutaml
|
|
2
|
-
module Model
|
|
3
|
-
module Mapping
|
|
4
|
-
end
|
|
5
|
-
end
|
|
6
|
-
end
|
|
7
|
-
|
|
8
|
-
require_relative "mapping/mapping_rule"
|
|
9
|
-
require_relative "mapping/yaml_mapping"
|
|
10
|
-
require_relative "mapping/json_mapping"
|
|
11
|
-
require_relative "mapping/toml_mapping"
|
|
12
|
-
require_relative "mapping/key_value_mapping_rule"
|
|
13
|
-
require_relative "mapping/xml_mapping"
|
|
14
|
-
require_relative "mapping/xml_mapping_rule"
|