lutaml 0.11.7 → 0.11.8

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.
Files changed (881) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +20 -0
  3. data/.rubocop_todo.yml +0 -1
  4. data/Gemfile +32 -5
  5. data/README.adoc +3 -3
  6. data/README.md +6 -8
  7. data/Rakefile +41 -1
  8. data/bin/console +0 -1
  9. data/exe/lutaml-lml +6 -0
  10. data/exe/lutaml-lml-lsp +11 -0
  11. data/lib/compat/opal/generate_boot.rb +132 -0
  12. data/lib/compat/opal/js_bundle_entry.rb +42 -0
  13. data/lib/compat/opal/lutaml_model_boot.rb +540 -0
  14. data/lib/compat/opal/monitor.rb +31 -0
  15. data/lib/compat/opal/moxml/adapter/customized_rexml/entity_reference.rb +9 -0
  16. data/lib/compat/opal/moxml/adapter/customized_rexml/formatter.rb +225 -0
  17. data/lib/compat/opal/moxml/adapter/customized_rexml.rb +11 -0
  18. data/lib/compat/opal/moxml_boot.rb +68 -0
  19. data/lib/compat/opal/objectspace_shim.rb +23 -0
  20. data/lib/compat/opal/rexml/namespace.rb +59 -0
  21. data/lib/compat/opal/rexml/parsers/baseparser.rb +1016 -0
  22. data/lib/compat/opal/rexml/source.rb +214 -0
  23. data/lib/compat/opal/rexml/text.rb +426 -0
  24. data/lib/compat/opal/rexml/xmltokens.rb +45 -0
  25. data/lib/compat/opal/rexml_compat.rb +85 -0
  26. data/lib/compat/opal/yaml_compat.rb +32 -0
  27. data/lib/lutaml/hash_format/adapter/document.rb +10 -0
  28. data/lib/lutaml/hash_format/adapter/mapping.rb +17 -0
  29. data/lib/lutaml/hash_format/adapter/mapping_rule.rb +9 -0
  30. data/lib/lutaml/hash_format/adapter/standard_adapter.rb +17 -0
  31. data/lib/lutaml/hash_format/adapter/transform.rb +9 -0
  32. data/lib/lutaml/hash_format/adapter.rb +13 -0
  33. data/lib/lutaml/hash_format/format.rb +29 -0
  34. data/lib/lutaml/hash_format/type/serializers.rb +24 -0
  35. data/lib/lutaml/hash_format.rb +7 -0
  36. data/lib/lutaml/json/adapter/document.rb +13 -0
  37. data/lib/lutaml/json/adapter/mapping.rb +17 -0
  38. data/lib/lutaml/json/adapter/mapping_rule.rb +9 -0
  39. data/lib/lutaml/json/adapter/multi_json_adapter.rb +45 -0
  40. data/lib/lutaml/json/adapter/oj_adapter.rb +41 -0
  41. data/lib/lutaml/json/adapter/standard_adapter.rb +43 -0
  42. data/lib/lutaml/json/adapter/transform.rb +9 -0
  43. data/lib/lutaml/json/adapter/yeptris_adapter.rb +74 -0
  44. data/lib/lutaml/json/adapter.rb +21 -0
  45. data/lib/lutaml/json/format.rb +61 -0
  46. data/lib/lutaml/json/generator_options.rb +62 -0
  47. data/lib/lutaml/json/schema/json_schema.rb +62 -0
  48. data/lib/lutaml/json/schema.rb +9 -0
  49. data/lib/lutaml/json/type/serializers.rb +72 -0
  50. data/lib/lutaml/json.rb +7 -0
  51. data/lib/lutaml/jsonl/adapter/document.rb +14 -0
  52. data/lib/lutaml/jsonl/adapter/mapping.rb +17 -0
  53. data/lib/lutaml/jsonl/adapter/mapping_rule.rb +9 -0
  54. data/lib/lutaml/jsonl/adapter/standard_adapter.rb +34 -0
  55. data/lib/lutaml/jsonl/adapter/transform.rb +26 -0
  56. data/lib/lutaml/jsonl/adapter.rb +13 -0
  57. data/lib/lutaml/jsonl/format.rb +22 -0
  58. data/lib/lutaml/jsonl.rb +7 -0
  59. data/lib/lutaml/jsonld/adapter.rb +31 -0
  60. data/lib/lutaml/jsonld.rb +20 -0
  61. data/lib/lutaml/key_value/adapter/hash/document.rb +13 -0
  62. data/lib/lutaml/key_value/adapter/hash/mapping.rb +17 -0
  63. data/lib/lutaml/key_value/adapter/hash/mapping_rule.rb +9 -0
  64. data/lib/lutaml/key_value/adapter/hash/standard_adapter.rb +19 -0
  65. data/lib/lutaml/key_value/adapter/hash/transform.rb +10 -0
  66. data/lib/lutaml/key_value/adapter/hash.rb +15 -0
  67. data/lib/lutaml/key_value/adapter/json/document.rb +16 -0
  68. data/lib/lutaml/key_value/adapter/json/mapping.rb +22 -0
  69. data/lib/lutaml/key_value/adapter/json/mapping_rule.rb +14 -0
  70. data/lib/lutaml/key_value/adapter/json/multi_json_adapter.rb +54 -0
  71. data/lib/lutaml/key_value/adapter/json/oj_adapter.rb +46 -0
  72. data/lib/lutaml/key_value/adapter/json/standard_adapter.rb +47 -0
  73. data/lib/lutaml/key_value/adapter/json/transform.rb +14 -0
  74. data/lib/lutaml/key_value/adapter/json/yeptris_adapter.rb +15 -0
  75. data/lib/lutaml/key_value/adapter/json.rb +24 -0
  76. data/lib/lutaml/key_value/adapter/jsonl/document.rb +16 -0
  77. data/lib/lutaml/key_value/adapter/jsonl/mapping.rb +17 -0
  78. data/lib/lutaml/key_value/adapter/jsonl/mapping_rule.rb +9 -0
  79. data/lib/lutaml/key_value/adapter/jsonl/standard_adapter.rb +36 -0
  80. data/lib/lutaml/key_value/adapter/jsonl/transform.rb +26 -0
  81. data/lib/lutaml/key_value/adapter/jsonl.rb +17 -0
  82. data/lib/lutaml/key_value/adapter/toml/document.rb +13 -0
  83. data/lib/lutaml/key_value/adapter/toml/mapping.rb +26 -0
  84. data/lib/lutaml/key_value/adapter/toml/mapping_rule.rb +9 -0
  85. data/lib/lutaml/key_value/adapter/toml/teptris_adapter.rb +36 -0
  86. data/lib/lutaml/key_value/adapter/toml/toml_rb_adapter.rb +34 -0
  87. data/lib/lutaml/key_value/adapter/toml/tomlib_adapter.rb +40 -0
  88. data/lib/lutaml/key_value/adapter/toml/transform.rb +10 -0
  89. data/lib/lutaml/key_value/adapter/toml.rb +22 -0
  90. data/lib/lutaml/key_value/adapter/yaml/document.rb +12 -0
  91. data/lib/lutaml/key_value/adapter/yaml/mapping.rb +17 -0
  92. data/lib/lutaml/key_value/adapter/yaml/mapping_rule.rb +9 -0
  93. data/lib/lutaml/key_value/adapter/yaml/standard_adapter.rb +35 -0
  94. data/lib/lutaml/key_value/adapter/yaml/transform.rb +10 -0
  95. data/lib/lutaml/key_value/adapter/yaml/yeptris_adapter.rb +15 -0
  96. data/lib/lutaml/key_value/adapter/yaml.rb +17 -0
  97. data/lib/lutaml/key_value/adapter/yamls/document.rb +16 -0
  98. data/lib/lutaml/key_value/adapter/yamls/mapping.rb +17 -0
  99. data/lib/lutaml/key_value/adapter/yamls/mapping_rule.rb +9 -0
  100. data/lib/lutaml/key_value/adapter/yamls/standard_adapter.rb +37 -0
  101. data/lib/lutaml/key_value/adapter/yamls/transform.rb +26 -0
  102. data/lib/lutaml/key_value/adapter/yamls.rb +17 -0
  103. data/lib/lutaml/key_value/adapter.rb +14 -0
  104. data/lib/lutaml/key_value/data_model/element.rb +225 -0
  105. data/lib/lutaml/key_value/data_model.rb +14 -0
  106. data/lib/lutaml/key_value/document.rb +28 -0
  107. data/lib/lutaml/key_value/format.rb +26 -0
  108. data/lib/lutaml/key_value/mapping.rb +393 -0
  109. data/lib/lutaml/key_value/mapping_rule.rb +95 -0
  110. data/lib/lutaml/key_value/transform.rb +1223 -0
  111. data/lib/lutaml/key_value/transformation/collection_serializer.rb +572 -0
  112. data/lib/lutaml/key_value/transformation/rule_compiler.rb +299 -0
  113. data/lib/lutaml/key_value/transformation/value_serializer.rb +399 -0
  114. data/lib/lutaml/key_value/transformation.rb +1276 -0
  115. data/lib/lutaml/key_value/transformation_builder.rb +30 -0
  116. data/lib/lutaml/key_value.rb +7 -0
  117. data/lib/lutaml/lml/association_label_resolver.rb +52 -0
  118. data/lib/lutaml/lml/cli.rb +506 -0
  119. data/lib/lutaml/lml/data_processor/attribute_processing.rb +133 -0
  120. data/lib/lutaml/lml/data_processor/collection_processing.rb +37 -0
  121. data/lib/lutaml/lml/data_processor/instance_processing.rb +77 -0
  122. data/lib/lutaml/lml/data_processor/value_declaration_processing.rb +70 -0
  123. data/lib/lutaml/lml/data_processor/value_processing.rb +103 -0
  124. data/lib/lutaml/lml/data_processor/view_processing.rb +26 -0
  125. data/lib/lutaml/lml/data_processor.rb +59 -0
  126. data/lib/lutaml/lml/diagnostic.rb +149 -0
  127. data/lib/lutaml/lml/document_builder.rb +481 -0
  128. data/lib/lutaml/lml/entity_types.rb +30 -0
  129. data/lib/lutaml/lml/executor/adapter_helpers.rb +45 -0
  130. data/lib/lutaml/lml/executor/condition_evaluator.rb +169 -0
  131. data/lib/lutaml/lml/executor/csv_adapter.rb +88 -0
  132. data/lib/lutaml/lml/executor/format_adapter.rb +54 -0
  133. data/lib/lutaml/lml/executor/xml_adapter.rb +102 -0
  134. data/lib/lutaml/lml/executor.rb +96 -0
  135. data/lib/lutaml/lml/format/adapter/document.rb +11 -0
  136. data/lib/lutaml/lml/format/adapter/mapping.rb +31 -0
  137. data/lib/lutaml/lml/format/adapter/standard_adapter.rb +162 -0
  138. data/lib/lutaml/lml/format/adapter/transform.rb +11 -0
  139. data/lib/lutaml/lml/format.rb +29 -0
  140. data/lib/lutaml/lml/formatter/base.rb +79 -0
  141. data/lib/lutaml/lml/formatter/canonical.rb +736 -0
  142. data/lib/lutaml/lml/formatter/elk.rb +45 -0
  143. data/lib/lutaml/lml/formatter/svg_pdf/path_parser.rb +134 -0
  144. data/lib/lutaml/lml/formatter/svg_pdf.rb +285 -0
  145. data/lib/lutaml/lml/formatter.rb +11 -0
  146. data/lib/lutaml/lml/grammar/lml.artifact.json +14993 -0
  147. data/lib/lutaml/lml/grammar/lml.parg +389 -0
  148. data/lib/lutaml/lml/grammar.rb +60 -0
  149. data/lib/lutaml/lml/has_attributes.rb +14 -0
  150. data/lib/lutaml/lml/import_resolver.rb +96 -0
  151. data/lib/lutaml/lml/layout/elk_engine.rb +15 -0
  152. data/lib/lutaml/lml/layout/elk_graph_builder.rb +129 -0
  153. data/lib/lutaml/lml/layout/elk_svg_markers.rb +45 -0
  154. data/lib/lutaml/lml/layout/elk_svg_renderer.rb +119 -0
  155. data/lib/lutaml/lml/layout/engine.rb +17 -0
  156. data/lib/lutaml/lml/layout.rb +12 -0
  157. data/lib/lutaml/lml/literal_value.rb +32 -0
  158. data/lib/lutaml/lml/lsp/conversions.rb +78 -0
  159. data/lib/lutaml/lml/lsp/keywords.rb +43 -0
  160. data/lib/lutaml/lml/lsp/server.rb +378 -0
  161. data/lib/lutaml/lml/lsp/store.rb +68 -0
  162. data/lib/lutaml/lml/lsp/transport.rb +53 -0
  163. data/lib/lutaml/lml/lsp.rb +16 -0
  164. data/lib/lutaml/lml/model_compiler/enums.rb +172 -0
  165. data/lib/lutaml/lml/model_compiler/hydration.rb +123 -0
  166. data/lib/lutaml/lml/model_compiler/serialization_mappings.rb +188 -0
  167. data/lib/lutaml/lml/model_compiler/string_formats.rb +42 -0
  168. data/lib/lutaml/lml/model_compiler/validation.rb +65 -0
  169. data/lib/lutaml/lml/model_compiler.rb +323 -0
  170. data/lib/lutaml/lml/models/action.rb +10 -0
  171. data/lib/lutaml/lml/models/association.rb +29 -0
  172. data/lib/lutaml/lml/models/cardinality.rb +10 -0
  173. data/lib/lutaml/lml/models/collection.rb +11 -0
  174. data/lib/lutaml/lml/models/constraint.rb +23 -0
  175. data/lib/lutaml/lml/models/data_type.rb +41 -0
  176. data/lib/lutaml/lml/models/derived_field.rb +14 -0
  177. data/lib/lutaml/lml/models/diagram.rb +20 -0
  178. data/lib/lutaml/lml/models/document.rb +84 -0
  179. data/lib/lutaml/lml/models/enum.rb +38 -0
  180. data/lib/lutaml/lml/models/fidelity.rb +10 -0
  181. data/lib/lutaml/lml/models/group.rb +11 -0
  182. data/lib/lutaml/lml/models/instance.rb +26 -0
  183. data/lib/lutaml/lml/models/instance_collection.rb +16 -0
  184. data/lib/lutaml/lml/models/instances_export.rb +10 -0
  185. data/lib/lutaml/lml/models/instances_import.rb +11 -0
  186. data/lib/lutaml/lml/models/mapping.rb +15 -0
  187. data/lib/lutaml/lml/models/mapping_rule.rb +16 -0
  188. data/lib/lutaml/lml/models/member_field.rb +14 -0
  189. data/lib/lutaml/lml/models/namespace.rb +16 -0
  190. data/lib/lutaml/lml/models/operation.rb +26 -0
  191. data/lib/lutaml/lml/models/operation_parameter.rb +12 -0
  192. data/lib/lutaml/lml/models/package.rb +26 -0
  193. data/lib/lutaml/lml/models/primitive_type.rb +33 -0
  194. data/lib/lutaml/lml/models/reference.rb +23 -0
  195. data/lib/lutaml/lml/models/serialization_mapping.rb +19 -0
  196. data/lib/lutaml/lml/models/string_format.rb +16 -0
  197. data/lib/lutaml/lml/models/top_element_attribute.rb +116 -0
  198. data/lib/lutaml/lml/models/uml_class.rb +85 -0
  199. data/lib/lutaml/lml/models/value.rb +15 -0
  200. data/lib/lutaml/lml/models/view_filter.rb +11 -0
  201. data/lib/lutaml/lml/models/view_import.rb +11 -0
  202. data/lib/lutaml/lml/parser.rb +19 -0
  203. data/lib/lutaml/lml/pipeline.rb +73 -0
  204. data/lib/lutaml/lml/positioned.rb +13 -0
  205. data/lib/lutaml/lml/preprocessor.rb +130 -0
  206. data/lib/lutaml/lml/quoting.rb +60 -0
  207. data/lib/lutaml/lml/source.rb +49 -0
  208. data/lib/lutaml/lml/source_position.rb +20 -0
  209. data/lib/lutaml/lml/symbol_index.rb +200 -0
  210. data/lib/lutaml/lml/transform.rb +119 -0
  211. data/lib/lutaml/lml/types/text_type.rb +28 -0
  212. data/lib/lutaml/lml/types.rb +10 -0
  213. data/lib/lutaml/lml/validator.rb +458 -0
  214. data/lib/lutaml/lml/version.rb +10 -0
  215. data/lib/lutaml/lml/view_resolution.rb +32 -0
  216. data/lib/lutaml/lml/view_resolver.rb +48 -0
  217. data/lib/lutaml/lml/yaml_parser.rb +17 -0
  218. data/lib/lutaml/lml.rb +130 -0
  219. data/lib/lutaml/model/adapter_resolver.rb +487 -0
  220. data/lib/lutaml/model/adapter_scope.rb +64 -0
  221. data/lib/lutaml/model/attribute.rb +1511 -0
  222. data/lib/lutaml/model/attribute_validator.rb +290 -0
  223. data/lib/lutaml/model/cached_type_resolver/concurrent_map_cache.rb +48 -0
  224. data/lib/lutaml/model/cached_type_resolver/mutex_hash_cache.rb +53 -0
  225. data/lib/lutaml/model/cached_type_resolver.rb +145 -0
  226. data/lib/lutaml/model/choice.rb +343 -0
  227. data/lib/lutaml/model/cli.rb +85 -0
  228. data/lib/lutaml/model/collection.rb +740 -0
  229. data/lib/lutaml/model/collection_handler.rb +157 -0
  230. data/lib/lutaml/model/comparable_model.rb +710 -0
  231. data/lib/lutaml/model/comparable_nil.rb +9 -0
  232. data/lib/lutaml/model/comparison.rb +15 -0
  233. data/lib/lutaml/model/compiled_rule.rb +242 -0
  234. data/lib/lutaml/model/config.rb +169 -0
  235. data/lib/lutaml/model/configuration.rb +138 -0
  236. data/lib/lutaml/model/consolidation/attribute_grouper.rb +44 -0
  237. data/lib/lutaml/model/consolidation/dispatcher.rb +45 -0
  238. data/lib/lutaml/model/consolidation/engine.rb +33 -0
  239. data/lib/lutaml/model/consolidation/pattern_chunker.rb +87 -0
  240. data/lib/lutaml/model/consolidation_map.rb +68 -0
  241. data/lib/lutaml/model/consolidation_rule/dispatch_block.rb +34 -0
  242. data/lib/lutaml/model/consolidation_rule/gather_rule.rb +17 -0
  243. data/lib/lutaml/model/consolidation_rule/pattern_content_rule.rb +15 -0
  244. data/lib/lutaml/model/consolidation_rule/pattern_element_rule.rb +17 -0
  245. data/lib/lutaml/model/consolidation_rule.rb +27 -0
  246. data/lib/lutaml/model/constants.rb +11 -0
  247. data/lib/lutaml/model/context_registry.rb +208 -0
  248. data/lib/lutaml/model/deep_dupable.rb +16 -0
  249. data/lib/lutaml/model/error/choice_lower_bound_error.rb +9 -0
  250. data/lib/lutaml/model/error/choice_upper_bound_error.rb +9 -0
  251. data/lib/lutaml/model/error/collection_count_out_of_range_error.rb +29 -0
  252. data/lib/lutaml/model/error/collection_true_missing_error.rb +16 -0
  253. data/lib/lutaml/model/error/element_count_out_of_range_error.rb +35 -0
  254. data/lib/lutaml/model/error/format_adapter_not_specified_error.rb +25 -0
  255. data/lib/lutaml/model/error/fraction_digits_error.rb +20 -0
  256. data/lib/lutaml/model/error/import_model_with_root_error.rb +9 -0
  257. data/lib/lutaml/model/error/incorrect_mapping_argument_error.rb +6 -0
  258. data/lib/lutaml/model/error/incorrect_sequence_error.rb +9 -0
  259. data/lib/lutaml/model/error/invalid_attribute_name_error.rb +15 -0
  260. data/lib/lutaml/model/error/invalid_attribute_options_error.rb +16 -0
  261. data/lib/lutaml/model/error/invalid_attribute_type_error.rb +98 -0
  262. data/lib/lutaml/model/error/invalid_choice_range_error.rb +18 -0
  263. data/lib/lutaml/model/error/invalid_format_error.rb +11 -0
  264. data/lib/lutaml/model/error/invalid_value_error.rb +18 -0
  265. data/lib/lutaml/model/error/length_error.rb +19 -0
  266. data/lib/lutaml/model/error/liquid_class_not_found_error.rb +9 -0
  267. data/lib/lutaml/model/error/liquid_drop_already_registered_error.rb +11 -0
  268. data/lib/lutaml/model/error/liquid_not_enabled_error.rb +9 -0
  269. data/lib/lutaml/model/error/mapping_already_exists_error.rb +6 -0
  270. data/lib/lutaml/model/error/mapping_attribute_missing_error.rb +6 -0
  271. data/lib/lutaml/model/error/mapping_attribute_type_error.rb +6 -0
  272. data/lib/lutaml/model/error/max_exclusive_error.rb +19 -0
  273. data/lib/lutaml/model/error/max_inclusive_error.rb +20 -0
  274. data/lib/lutaml/model/error/max_length_error.rb +20 -0
  275. data/lib/lutaml/model/error/min_exclusive_error.rb +19 -0
  276. data/lib/lutaml/model/error/min_inclusive_error.rb +20 -0
  277. data/lib/lutaml/model/error/min_length_error.rb +20 -0
  278. data/lib/lutaml/model/error/mixed_content_collection_error.rb +17 -0
  279. data/lib/lutaml/model/error/multiple_mappings_error.rb +6 -0
  280. data/lib/lutaml/model/error/no_attributes_defined_liquid_error.rb +9 -0
  281. data/lib/lutaml/model/error/no_mapping_found_error.rb +9 -0
  282. data/lib/lutaml/model/error/no_root_mapping_error.rb +10 -0
  283. data/lib/lutaml/model/error/no_root_namespace_error.rb +10 -0
  284. data/lib/lutaml/model/error/ordered_content_mapping_error.rb +17 -0
  285. data/lib/lutaml/model/error/pattern_not_matched_error.rb +17 -0
  286. data/lib/lutaml/model/error/polymorphic_error.rb +14 -0
  287. data/lib/lutaml/model/error/register/not_registrable_class_error.rb +11 -0
  288. data/lib/lutaml/model/error/required_attribute_missing_error.rb +9 -0
  289. data/lib/lutaml/model/error/restriction_error.rb +8 -0
  290. data/lib/lutaml/model/error/reverse_transform_block_not_defined_error.rb +6 -0
  291. data/lib/lutaml/model/error/reverse_transformation_declaration_error.rb +6 -0
  292. data/lib/lutaml/model/error/sorting_configuration_conflict_error.rb +9 -0
  293. data/lib/lutaml/model/error/total_digits_error.rb +20 -0
  294. data/lib/lutaml/model/error/transform_block_not_defined_error.rb +6 -0
  295. data/lib/lutaml/model/error/type/invalid_value_error.rb +21 -0
  296. data/lib/lutaml/model/error/type/max_bound_error.rb +20 -0
  297. data/lib/lutaml/model/error/type/max_exclusive_error.rb +20 -0
  298. data/lib/lutaml/model/error/type/max_length_error.rb +20 -0
  299. data/lib/lutaml/model/error/type/min_bound_error.rb +20 -0
  300. data/lib/lutaml/model/error/type/min_exclusive_error.rb +20 -0
  301. data/lib/lutaml/model/error/type/min_length_error.rb +20 -0
  302. data/lib/lutaml/model/error/type/pattern_not_matched_error.rb +18 -0
  303. data/lib/lutaml/model/error/type.rb +19 -0
  304. data/lib/lutaml/model/error/type_error.rb +9 -0
  305. data/lib/lutaml/model/error/type_not_enabled_error.rb +9 -0
  306. data/lib/lutaml/model/error/type_only_mapping_error.rb +13 -0
  307. data/lib/lutaml/model/error/type_only_namespace_error.rb +12 -0
  308. data/lib/lutaml/model/error/undefined_attribute_error.rb +9 -0
  309. data/lib/lutaml/model/error/union_schema_unsupported_error.rb +11 -0
  310. data/lib/lutaml/model/error/unknown_adapter_type_error.rb +95 -0
  311. data/lib/lutaml/model/error/unknown_discriminator_error.rb +11 -0
  312. data/lib/lutaml/model/error/unknown_mapping_error.rb +18 -0
  313. data/lib/lutaml/model/error/unknown_sequence_mapping_error.rb +9 -0
  314. data/lib/lutaml/model/error/unknown_type_error.rb +32 -0
  315. data/lib/lutaml/model/error/unresolvable_type_error.rb +27 -0
  316. data/lib/lutaml/model/error/unsupported_version_error.rb +14 -0
  317. data/lib/lutaml/model/error/validation_error.rb +20 -0
  318. data/lib/lutaml/model/error/validation_failed_error.rb +9 -0
  319. data/lib/lutaml/model/error.rb +8 -0
  320. data/lib/lutaml/model/errors.rb +38 -0
  321. data/lib/lutaml/model/evolution_steps.rb +85 -0
  322. data/lib/lutaml/model/finalization_cache.rb +51 -0
  323. data/lib/lutaml/model/format_registry.rb +218 -0
  324. data/lib/lutaml/model/global_context.rb +476 -0
  325. data/lib/lutaml/model/global_register.rb +142 -0
  326. data/lib/lutaml/model/hash.rb +15 -0
  327. data/lib/lutaml/model/import_registry.rb +250 -0
  328. data/lib/lutaml/model/instrumentation.rb +304 -0
  329. data/lib/lutaml/model/json.rb +25 -0
  330. data/lib/lutaml/model/json_adapter.rb +8 -0
  331. data/lib/lutaml/model/jsonl.rb +15 -0
  332. data/lib/lutaml/model/liquefiable.rb +198 -0
  333. data/lib/lutaml/model/liquid/indexed_access.rb +33 -0
  334. data/lib/lutaml/model/liquid/mapping.rb +30 -0
  335. data/lib/lutaml/model/liquid.rb +10 -0
  336. data/lib/lutaml/model/lml/document.rb +109 -0
  337. data/lib/lutaml/model/lml/exporter.rb +328 -0
  338. data/lib/lutaml/model/lml/rejected_error.rb +32 -0
  339. data/lib/lutaml/model/lml/round_trip.rb +49 -0
  340. data/lib/lutaml/model/lml.rb +40 -0
  341. data/lib/lutaml/model/mapping/listener.rb +126 -0
  342. data/lib/lutaml/model/mapping/mapping.rb +209 -0
  343. data/lib/lutaml/model/mapping/mapping_rule.rb +673 -0
  344. data/lib/lutaml/model/mapping/model_mapping.rb +133 -0
  345. data/lib/lutaml/model/mapping/model_mapping_rule.rb +57 -0
  346. data/lib/lutaml/model/mapping_hash.rb +80 -0
  347. data/lib/lutaml/model/model_transformer.rb +101 -0
  348. data/lib/lutaml/model/one_entry_cache.rb +57 -0
  349. data/lib/lutaml/model/organization.rb +29 -0
  350. data/lib/lutaml/model/register/model_tree_importer.rb +88 -0
  351. data/lib/lutaml/model/register/namespace_binding.rb +92 -0
  352. data/lib/lutaml/model/register.rb +589 -0
  353. data/lib/lutaml/model/registrable.rb +8 -0
  354. data/lib/lutaml/model/render_policy.rb +166 -0
  355. data/lib/lutaml/model/restriction_validation.rb +437 -0
  356. data/lib/lutaml/model/runtime_compatibility.rb +144 -0
  357. data/lib/lutaml/model/schema/base_schema.rb +77 -0
  358. data/lib/lutaml/model/schema/class_loader.rb +59 -0
  359. data/lib/lutaml/model/schema/compiled_output.rb +83 -0
  360. data/lib/lutaml/model/schema/decorators/attribute.rb +116 -0
  361. data/lib/lutaml/model/schema/decorators/choices.rb +29 -0
  362. data/lib/lutaml/model/schema/decorators/class_definition.rb +84 -0
  363. data/lib/lutaml/model/schema/decorators/definition_collection.rb +97 -0
  364. data/lib/lutaml/model/schema/decorators.rb +15 -0
  365. data/lib/lutaml/model/schema/definitions/attribute.rb +32 -0
  366. data/lib/lutaml/model/schema/definitions/choice.rb +20 -0
  367. data/lib/lutaml/model/schema/definitions/facet.rb +40 -0
  368. data/lib/lutaml/model/schema/definitions/group_import.rb +22 -0
  369. data/lib/lutaml/model/schema/definitions/member_walk.rb +33 -0
  370. data/lib/lutaml/model/schema/definitions/model.rb +40 -0
  371. data/lib/lutaml/model/schema/definitions/namespace.rb +24 -0
  372. data/lib/lutaml/model/schema/definitions/restricted_type.rb +32 -0
  373. data/lib/lutaml/model/schema/definitions/sequence.rb +19 -0
  374. data/lib/lutaml/model/schema/definitions/simple_content.rb +22 -0
  375. data/lib/lutaml/model/schema/definitions/transform_facet.rb +21 -0
  376. data/lib/lutaml/model/schema/definitions/type_ref.rb +20 -0
  377. data/lib/lutaml/model/schema/definitions/union_type.rb +28 -0
  378. data/lib/lutaml/model/schema/definitions/xml_root.rb +20 -0
  379. data/lib/lutaml/model/schema/definitions.rb +24 -0
  380. data/lib/lutaml/model/schema/file_writer.rb +73 -0
  381. data/lib/lutaml/model/schema/generator/definition.rb +98 -0
  382. data/lib/lutaml/model/schema/generator/definitions_collection.rb +117 -0
  383. data/lib/lutaml/model/schema/generator/properties_collection.rb +65 -0
  384. data/lib/lutaml/model/schema/generator/property.rb +182 -0
  385. data/lib/lutaml/model/schema/generator/ref.rb +24 -0
  386. data/lib/lutaml/model/schema/generator.rb +15 -0
  387. data/lib/lutaml/model/schema/helpers/template_helper.rb +49 -0
  388. data/lib/lutaml/model/schema/helpers.rb +11 -0
  389. data/lib/lutaml/model/schema/json_schema.rb +17 -0
  390. data/lib/lutaml/model/schema/json_schema_parser.rb +91 -0
  391. data/lib/lutaml/model/schema/module_nesting.rb +31 -0
  392. data/lib/lutaml/model/schema/namespace_naming.rb +46 -0
  393. data/lib/lutaml/model/schema/registry_generator.rb +115 -0
  394. data/lib/lutaml/model/schema/renderer.rb +38 -0
  395. data/lib/lutaml/model/schema/renderers/base.rb +41 -0
  396. data/lib/lutaml/model/schema/renderers/mappings.rb +78 -0
  397. data/lib/lutaml/model/schema/renderers/member_decls.rb +121 -0
  398. data/lib/lutaml/model/schema/renderers/model.rb +133 -0
  399. data/lib/lutaml/model/schema/renderers/namespace.rb +30 -0
  400. data/lib/lutaml/model/schema/renderers/registration.rb +64 -0
  401. data/lib/lutaml/model/schema/renderers/required_files_calculator.rb +94 -0
  402. data/lib/lutaml/model/schema/renderers/restricted_type.rb +218 -0
  403. data/lib/lutaml/model/schema/renderers/union.rb +83 -0
  404. data/lib/lutaml/model/schema/renderers.rb +20 -0
  405. data/lib/lutaml/model/schema/rnc_compiler/source_resolver.rb +51 -0
  406. data/lib/lutaml/model/schema/rnc_compiler.rb +64 -0
  407. data/lib/lutaml/model/schema/rng_compiler/define_classifier.rb +94 -0
  408. data/lib/lutaml/model/schema/rng_compiler/element_visitor.rb +412 -0
  409. data/lib/lutaml/model/schema/rng_compiler/member_collector.rb +30 -0
  410. data/lib/lutaml/model/schema/rng_compiler/rng_helpers.rb +160 -0
  411. data/lib/lutaml/model/schema/rng_compiler/value_type_resolver.rb +129 -0
  412. data/lib/lutaml/model/schema/rng_compiler.rb +225 -0
  413. data/lib/lutaml/model/schema/schema_builder/nokogiri.rb +41 -0
  414. data/lib/lutaml/model/schema/schema_builder/oga.rb +92 -0
  415. data/lib/lutaml/model/schema/shared_methods.rb +24 -0
  416. data/lib/lutaml/model/schema/templates/model.erb +9 -0
  417. data/lib/lutaml/model/schema/templates.rb +164 -0
  418. data/lib/lutaml/model/schema/xml_compiler/element_order.rb +42 -0
  419. data/lib/lutaml/model/schema/xml_compiler/registry_generator.rb +51 -0
  420. data/lib/lutaml/model/schema/xml_compiler/spec_builder/complex_types.rb +198 -0
  421. data/lib/lutaml/model/schema/xml_compiler/spec_builder/members.rb +249 -0
  422. data/lib/lutaml/model/schema/xml_compiler/spec_builder/simple_types.rb +185 -0
  423. data/lib/lutaml/model/schema/xml_compiler/spec_builder.rb +186 -0
  424. data/lib/lutaml/model/schema/xml_compiler/supported_data_types.rb +100 -0
  425. data/lib/lutaml/model/schema/xml_compiler.rb +109 -0
  426. data/lib/lutaml/model/schema/yaml_schema.rb +17 -0
  427. data/lib/lutaml/model/schema.rb +88 -0
  428. data/lib/lutaml/model/schema_location.rb +18 -0
  429. data/lib/lutaml/model/sequence.rb +220 -0
  430. data/lib/lutaml/model/serializable.rb +46 -0
  431. data/lib/lutaml/model/serialization_adapter.rb +24 -0
  432. data/lib/lutaml/model/serialize/attribute_definition.rb +897 -0
  433. data/lib/lutaml/model/serialize/builder.rb +258 -0
  434. data/lib/lutaml/model/serialize/conversion_caching.rb +129 -0
  435. data/lib/lutaml/model/serialize/deserialization_context.rb +51 -0
  436. data/lib/lutaml/model/serialize/enum_handling.rb +171 -0
  437. data/lib/lutaml/model/serialize/format_conversion.rb +624 -0
  438. data/lib/lutaml/model/serialize/initialization.rb +825 -0
  439. data/lib/lutaml/model/serialize/model_import.rb +425 -0
  440. data/lib/lutaml/model/serialize/transformation_builder.rb +128 -0
  441. data/lib/lutaml/model/serialize/value_mapping.rb +173 -0
  442. data/lib/lutaml/model/serialize.rb +533 -0
  443. data/lib/lutaml/model/services/base.rb +13 -0
  444. data/lib/lutaml/model/services/logger.rb +57 -0
  445. data/lib/lutaml/model/services/rule_value_extractor.rb +95 -0
  446. data/lib/lutaml/model/services/transformer.rb +143 -0
  447. data/lib/lutaml/model/services/type/validator/number.rb +25 -0
  448. data/lib/lutaml/model/services/type/validator/string.rb +53 -0
  449. data/lib/lutaml/model/services/type/validator/symbol.rb +30 -0
  450. data/lib/lutaml/model/services/type/validator.rb +69 -0
  451. data/lib/lutaml/model/services/type.rb +9 -0
  452. data/lib/lutaml/model/services/validator.rb +143 -0
  453. data/lib/lutaml/model/services.rb +10 -0
  454. data/lib/lutaml/model/store.rb +239 -0
  455. data/lib/lutaml/model/toml.rb +40 -0
  456. data/lib/lutaml/model/transform/xml_transform.rb +5 -0
  457. data/lib/lutaml/model/transform.rb +229 -0
  458. data/lib/lutaml/model/transformation.rb +89 -0
  459. data/lib/lutaml/model/transformation_builder.rb +55 -0
  460. data/lib/lutaml/model/transformation_registry.rb +327 -0
  461. data/lib/lutaml/model/type/base64_binary.rb +58 -0
  462. data/lib/lutaml/model/type/boolean.rb +35 -0
  463. data/lib/lutaml/model/type/date.rb +75 -0
  464. data/lib/lutaml/model/type/date_time.rb +60 -0
  465. data/lib/lutaml/model/type/date_time_with_timezone.rb +28 -0
  466. data/lib/lutaml/model/type/date_with_timezone.rb +28 -0
  467. data/lib/lutaml/model/type/day_time_duration.rb +35 -0
  468. data/lib/lutaml/model/type/decimal.rb +64 -0
  469. data/lib/lutaml/model/type/duration.rb +82 -0
  470. data/lib/lutaml/model/type/email_address.rb +28 -0
  471. data/lib/lutaml/model/type/float.rb +33 -0
  472. data/lib/lutaml/model/type/hash.rb +74 -0
  473. data/lib/lutaml/model/type/hex_binary.rb +56 -0
  474. data/lib/lutaml/model/type/hostname.rb +30 -0
  475. data/lib/lutaml/model/type/integer.rb +62 -0
  476. data/lib/lutaml/model/type/ip_v4_address.rb +27 -0
  477. data/lib/lutaml/model/type/ip_v6_address.rb +47 -0
  478. data/lib/lutaml/model/type/metaschema_pattern.rb +34 -0
  479. data/lib/lutaml/model/type/non_negative_integer.rb +25 -0
  480. data/lib/lutaml/model/type/positive_integer.rb +25 -0
  481. data/lib/lutaml/model/type/qname.rb +85 -0
  482. data/lib/lutaml/model/type/reference.rb +76 -0
  483. data/lib/lutaml/model/type/string.rb +62 -0
  484. data/lib/lutaml/model/type/symbol.rb +67 -0
  485. data/lib/lutaml/model/type/time.rb +52 -0
  486. data/lib/lutaml/model/type/time_without_date.rb +50 -0
  487. data/lib/lutaml/model/type/token.rb +25 -0
  488. data/lib/lutaml/model/type/uninitialized_class_guard.rb +36 -0
  489. data/lib/lutaml/model/type/uri.rb +51 -0
  490. data/lib/lutaml/model/type/uri_reference.rb +29 -0
  491. data/lib/lutaml/model/type/uuid.rb +25 -0
  492. data/lib/lutaml/model/type/value.rb +364 -0
  493. data/lib/lutaml/model/type/year_month_duration.rb +29 -0
  494. data/lib/lutaml/model/type.rb +199 -0
  495. data/lib/lutaml/model/type_context.rb +294 -0
  496. data/lib/lutaml/model/type_registry.rb +165 -0
  497. data/lib/lutaml/model/type_resolver.rb +187 -0
  498. data/lib/lutaml/model/type_substitution.rb +117 -0
  499. data/lib/lutaml/model/uninitialized_class.rb +70 -0
  500. data/lib/lutaml/model/union.rb +363 -0
  501. data/lib/lutaml/model/utils.rb +352 -0
  502. data/lib/lutaml/model/validation/concerns/has_issues.rb +27 -0
  503. data/lib/lutaml/model/validation/context.rb +36 -0
  504. data/lib/lutaml/model/validation/issue.rb +62 -0
  505. data/lib/lutaml/model/validation/layer_result.rb +34 -0
  506. data/lib/lutaml/model/validation/profile.rb +66 -0
  507. data/lib/lutaml/model/validation/registry.rb +60 -0
  508. data/lib/lutaml/model/validation/remediation.rb +33 -0
  509. data/lib/lutaml/model/validation/remediation_result.rb +20 -0
  510. data/lib/lutaml/model/validation/report.rb +39 -0
  511. data/lib/lutaml/model/validation/rule.rb +59 -0
  512. data/lib/lutaml/model/validation.rb +137 -0
  513. data/lib/lutaml/model/validation_framework.rb +77 -0
  514. data/lib/lutaml/model/value_policy.rb +27 -0
  515. data/lib/lutaml/model/value_transformer.rb +25 -0
  516. data/lib/lutaml/model/version.rb +7 -0
  517. data/lib/lutaml/model/yaml.rb +15 -0
  518. data/lib/lutaml/model/yamls.rb +15 -0
  519. data/lib/lutaml/model.rb +309 -0
  520. data/lib/lutaml/rdf/context.rb +69 -0
  521. data/lib/lutaml/rdf/error.rb +7 -0
  522. data/lib/lutaml/rdf/iri.rb +44 -0
  523. data/lib/lutaml/rdf/language_tagged.rb +11 -0
  524. data/lib/lutaml/rdf/linked_data_transform.rb +249 -0
  525. data/lib/lutaml/rdf/literal.rb +62 -0
  526. data/lib/lutaml/rdf/mapping.rb +86 -0
  527. data/lib/lutaml/rdf/mapping_rule.rb +52 -0
  528. data/lib/lutaml/rdf/member_rule.rb +55 -0
  529. data/lib/lutaml/rdf/namespace.rb +58 -0
  530. data/lib/lutaml/rdf/namespace_set.rb +69 -0
  531. data/lib/lutaml/rdf/namespaces/dcterms_namespace.rb +12 -0
  532. data/lib/lutaml/rdf/namespaces/owl_namespace.rb +12 -0
  533. data/lib/lutaml/rdf/namespaces/rdf_namespace.rb +14 -0
  534. data/lib/lutaml/rdf/namespaces/rdfs_namespace.rb +12 -0
  535. data/lib/lutaml/rdf/namespaces/skos_namespace.rb +12 -0
  536. data/lib/lutaml/rdf/namespaces/xsd_namespace.rb +12 -0
  537. data/lib/lutaml/rdf/namespaces.rb +14 -0
  538. data/lib/lutaml/rdf/term_definition.rb +39 -0
  539. data/lib/lutaml/rdf/transform.rb +45 -0
  540. data/lib/lutaml/rdf.rb +22 -0
  541. data/lib/lutaml/toml/adapter/document.rb +10 -0
  542. data/lib/lutaml/toml/adapter/mapping.rb +26 -0
  543. data/lib/lutaml/toml/adapter/mapping_rule.rb +9 -0
  544. data/lib/lutaml/toml/adapter/teptris_adapter.rb +14 -0
  545. data/lib/lutaml/toml/adapter/toml_rb_adapter.rb +32 -0
  546. data/lib/lutaml/toml/adapter/tomlib_adapter.rb +48 -0
  547. data/lib/lutaml/toml/adapter/transform.rb +9 -0
  548. data/lib/lutaml/toml/adapter.rb +20 -0
  549. data/lib/lutaml/toml/format.rb +48 -0
  550. data/lib/lutaml/toml/type/serializers.rb +71 -0
  551. data/lib/lutaml/toml.rb +7 -0
  552. data/lib/lutaml/turtle/adapter.rb +35 -0
  553. data/lib/lutaml/turtle/mapping.rb +7 -0
  554. data/lib/lutaml/turtle/transform.rb +250 -0
  555. data/lib/lutaml/turtle.rb +22 -0
  556. data/lib/lutaml/version.rb +1 -1
  557. data/lib/lutaml/xml/adapter/adapter_helpers.rb +108 -0
  558. data/lib/lutaml/xml/adapter/base_adapter.rb +249 -0
  559. data/lib/lutaml/xml/adapter/leptris_adapter.rb +16 -0
  560. data/lib/lutaml/xml/adapter/namespace_data.rb +56 -0
  561. data/lib/lutaml/xml/adapter/namespace_uri_collector.rb +71 -0
  562. data/lib/lutaml/xml/adapter/nokogiri_adapter.rb +16 -0
  563. data/lib/lutaml/xml/adapter/oga_adapter.rb +20 -0
  564. data/lib/lutaml/xml/adapter/ox_adapter.rb +16 -0
  565. data/lib/lutaml/xml/adapter/plan_based_builder.rb +944 -0
  566. data/lib/lutaml/xml/adapter/rexml_adapter.rb +25 -0
  567. data/lib/lutaml/xml/adapter/xml_parser.rb +89 -0
  568. data/lib/lutaml/xml/adapter/xml_serializer.rb +334 -0
  569. data/lib/lutaml/xml/adapter.rb +24 -0
  570. data/lib/lutaml/xml/adapter_element.rb +339 -0
  571. data/lib/lutaml/xml/adapter_loader.rb +56 -0
  572. data/lib/lutaml/xml/attribute_namespace_resolver.rb +139 -0
  573. data/lib/lutaml/xml/blank_namespace.rb +51 -0
  574. data/lib/lutaml/xml/blank_namespace_handler.rb +50 -0
  575. data/lib/lutaml/xml/builder/base.rb +258 -0
  576. data/lib/lutaml/xml/builder/leptris.rb +13 -0
  577. data/lib/lutaml/xml/builder/nokogiri.rb +13 -0
  578. data/lib/lutaml/xml/builder/oga.rb +13 -0
  579. data/lib/lutaml/xml/builder/ox.rb +13 -0
  580. data/lib/lutaml/xml/builder/rexml.rb +13 -0
  581. data/lib/lutaml/xml/builder.rb +18 -0
  582. data/lib/lutaml/xml/configurable.rb +215 -0
  583. data/lib/lutaml/xml/data_model.rb +295 -0
  584. data/lib/lutaml/xml/decisions/decision.rb +120 -0
  585. data/lib/lutaml/xml/decisions/decision_context.rb +225 -0
  586. data/lib/lutaml/xml/decisions/decision_engine.rb +67 -0
  587. data/lib/lutaml/xml/decisions/decision_rule.rb +54 -0
  588. data/lib/lutaml/xml/decisions/element_prefix_resolver.rb +85 -0
  589. data/lib/lutaml/xml/decisions/rules/attribute_usage_rule.rb +37 -0
  590. data/lib/lutaml/xml/decisions/rules/default_preference_rule.rb +62 -0
  591. data/lib/lutaml/xml/decisions/rules/element_form_default_rule.rb +66 -0
  592. data/lib/lutaml/xml/decisions/rules/element_form_default_unqualified_rule.rb +73 -0
  593. data/lib/lutaml/xml/decisions/rules/element_form_option_rule.rb +83 -0
  594. data/lib/lutaml/xml/decisions/rules/explicit_option_rule.rb +57 -0
  595. data/lib/lutaml/xml/decisions/rules/format_preservation_rule.rb +74 -0
  596. data/lib/lutaml/xml/decisions/rules/hoisted_on_parent_rule.rb +60 -0
  597. data/lib/lutaml/xml/decisions/rules/inherit_from_parent_rule.rb +52 -0
  598. data/lib/lutaml/xml/decisions/rules/inherit_parent_prefix_rule.rb +69 -0
  599. data/lib/lutaml/xml/decisions/rules/namespace_scope_rule.rb +54 -0
  600. data/lib/lutaml/xml/decisions/rules/reuse_parent_prefix_rule.rb +78 -0
  601. data/lib/lutaml/xml/decisions/rules/used_prefix_rule.rb +70 -0
  602. data/lib/lutaml/xml/decisions/rules.rb +39 -0
  603. data/lib/lutaml/xml/decisions.rb +15 -0
  604. data/lib/lutaml/xml/declaration_handler.rb +115 -0
  605. data/lib/lutaml/xml/declaration_plan/attribute_node.rb +81 -0
  606. data/lib/lutaml/xml/declaration_plan/element_node.rb +101 -0
  607. data/lib/lutaml/xml/declaration_plan.rb +480 -0
  608. data/lib/lutaml/xml/declaration_plan_query.rb +105 -0
  609. data/lib/lutaml/xml/declaration_planner.rb +1914 -0
  610. data/lib/lutaml/xml/doctype_extractor.rb +51 -0
  611. data/lib/lutaml/xml/document.rb +385 -0
  612. data/lib/lutaml/xml/element.rb +108 -0
  613. data/lib/lutaml/xml/element_prefix_resolver.rb +50 -0
  614. data/lib/lutaml/xml/encoding_normalizer.rb +54 -0
  615. data/lib/lutaml/xml/error/invalid_namespace_error.rb +46 -0
  616. data/lib/lutaml/xml/error/invalid_xsd_type_error.rb +43 -0
  617. data/lib/lutaml/xml/error/namespace_mismatch_error.rb +53 -0
  618. data/lib/lutaml/xml/error/schema_validation_error.rb +25 -0
  619. data/lib/lutaml/xml/error/xml_configuration_error.rb +17 -0
  620. data/lib/lutaml/xml/error/xml_error.rb +21 -0
  621. data/lib/lutaml/xml/format.rb +364 -0
  622. data/lib/lutaml/xml/format_chooser.rb +214 -0
  623. data/lib/lutaml/xml/hoisting_algorithm.rb +234 -0
  624. data/lib/lutaml/xml/html_entities.rb +290 -0
  625. data/lib/lutaml/xml/leptris/element.rb +34 -0
  626. data/lib/lutaml/xml/leptris/native_emission.rb +295 -0
  627. data/lib/lutaml/xml/leptris/plan_compiler.rb +652 -0
  628. data/lib/lutaml/xml/leptris/plan_hydrator.rb +827 -0
  629. data/lib/lutaml/xml/leptris/plan_order.rb +72 -0
  630. data/lib/lutaml/xml/leptris/plan_serializer.rb +711 -0
  631. data/lib/lutaml/xml/leptris/plan_walk.rb +36 -0
  632. data/lib/lutaml/xml/leptris.rb +48 -0
  633. data/lib/lutaml/xml/listener.rb +33 -0
  634. data/lib/lutaml/xml/mapping.rb +1746 -0
  635. data/lib/lutaml/xml/mapping_rule.rb +688 -0
  636. data/lib/lutaml/xml/model_transform.rb +1824 -0
  637. data/lib/lutaml/xml/namespace.rb +445 -0
  638. data/lib/lutaml/xml/namespace_class_registry.rb +144 -0
  639. data/lib/lutaml/xml/namespace_collector.rb +649 -0
  640. data/lib/lutaml/xml/namespace_declaration.rb +202 -0
  641. data/lib/lutaml/xml/namespace_declaration_builder.rb +67 -0
  642. data/lib/lutaml/xml/namespace_declaration_data.rb +179 -0
  643. data/lib/lutaml/xml/namespace_inheritance_resolver.rb +142 -0
  644. data/lib/lutaml/xml/namespace_inheritance_strategy.rb +26 -0
  645. data/lib/lutaml/xml/namespace_needs.rb +255 -0
  646. data/lib/lutaml/xml/namespace_resolution_strategy.rb +230 -0
  647. data/lib/lutaml/xml/namespace_resolver.rb +219 -0
  648. data/lib/lutaml/xml/namespace_scope_config.rb +110 -0
  649. data/lib/lutaml/xml/namespace_type_resolver.rb +135 -0
  650. data/lib/lutaml/xml/namespace_usage.rb +121 -0
  651. data/lib/lutaml/xml/nested_collection_attribute.rb +95 -0
  652. data/lib/lutaml/xml/nokogiri/element.rb +34 -0
  653. data/lib/lutaml/xml/nokogiri.rb +10 -0
  654. data/lib/lutaml/xml/oga/element.rb +15 -0
  655. data/lib/lutaml/xml/oga.rb +10 -0
  656. data/lib/lutaml/xml/ox/element.rb +15 -0
  657. data/lib/lutaml/xml/ox.rb +10 -0
  658. data/lib/lutaml/xml/parse_session.rb +139 -0
  659. data/lib/lutaml/xml/parsed_namespace_declaration.rb +129 -0
  660. data/lib/lutaml/xml/parsed_namespace_set.rb +149 -0
  661. data/lib/lutaml/xml/polymorphic_value_handler.rb +41 -0
  662. data/lib/lutaml/xml/qualified_inheritance_strategy.rb +27 -0
  663. data/lib/lutaml/xml/rexml/element.rb +15 -0
  664. data/lib/lutaml/xml/rexml.rb +10 -0
  665. data/lib/lutaml/xml/schema/builder/nokogiri.rb +41 -0
  666. data/lib/lutaml/xml/schema/builder/oga.rb +92 -0
  667. data/lib/lutaml/xml/schema/builder.rb +59 -0
  668. data/lib/lutaml/xml/schema/builtin_types.rb +112 -0
  669. data/lib/lutaml/xml/schema/relaxng_schema.rb +83 -0
  670. data/lib/lutaml/xml/schema/xsd/all.rb +31 -0
  671. data/lib/lutaml/xml/schema/xsd/annotation.rb +31 -0
  672. data/lib/lutaml/xml/schema/xsd/any.rb +33 -0
  673. data/lib/lutaml/xml/schema/xsd/any_attribute.rb +29 -0
  674. data/lib/lutaml/xml/schema/xsd/appinfo.rb +25 -0
  675. data/lib/lutaml/xml/schema/xsd/attribute.rb +78 -0
  676. data/lib/lutaml/xml/schema/xsd/attribute_group.rb +89 -0
  677. data/lib/lutaml/xml/schema/xsd/base.rb +270 -0
  678. data/lib/lutaml/xml/schema/xsd/choice.rb +68 -0
  679. data/lib/lutaml/xml/schema/xsd/complex_content.rb +39 -0
  680. data/lib/lutaml/xml/schema/xsd/complex_type.rb +159 -0
  681. data/lib/lutaml/xml/schema/xsd/documentation.rb +26 -0
  682. data/lib/lutaml/xml/schema/xsd/element.rb +117 -0
  683. data/lib/lutaml/xml/schema/xsd/enumeration.rb +25 -0
  684. data/lib/lutaml/xml/schema/xsd/errors/enhanced_error.rb +142 -0
  685. data/lib/lutaml/xml/schema/xsd/errors/error_context.rb +67 -0
  686. data/lib/lutaml/xml/schema/xsd/errors/message_builder.rb +103 -0
  687. data/lib/lutaml/xml/schema/xsd/errors/suggestion.rb +67 -0
  688. data/lib/lutaml/xml/schema/xsd/errors/troubleshooters/namespace_troubleshooter.rb +96 -0
  689. data/lib/lutaml/xml/schema/xsd/errors/troubleshooters/troubleshooting_handler.rb +70 -0
  690. data/lib/lutaml/xml/schema/xsd/errors.rb +148 -0
  691. data/lib/lutaml/xml/schema/xsd/extension_complex_content.rb +63 -0
  692. data/lib/lutaml/xml/schema/xsd/extension_simple_content.rb +48 -0
  693. data/lib/lutaml/xml/schema/xsd/field.rb +25 -0
  694. data/lib/lutaml/xml/schema/xsd/file_validation_result.rb +55 -0
  695. data/lib/lutaml/xml/schema/xsd/fraction_digits.rb +29 -0
  696. data/lib/lutaml/xml/schema/xsd/glob.rb +105 -0
  697. data/lib/lutaml/xml/schema/xsd/group.rb +79 -0
  698. data/lib/lutaml/xml/schema/xsd/import.rb +33 -0
  699. data/lib/lutaml/xml/schema/xsd/include.rb +31 -0
  700. data/lib/lutaml/xml/schema/xsd/key.rb +32 -0
  701. data/lib/lutaml/xml/schema/xsd/keyref.rb +34 -0
  702. data/lib/lutaml/xml/schema/xsd/length.rb +27 -0
  703. data/lib/lutaml/xml/schema/xsd/list.rb +29 -0
  704. data/lib/lutaml/xml/schema/xsd/max_exclusive.rb +25 -0
  705. data/lib/lutaml/xml/schema/xsd/max_inclusive.rb +23 -0
  706. data/lib/lutaml/xml/schema/xsd/max_length.rb +25 -0
  707. data/lib/lutaml/xml/schema/xsd/min_exclusive.rb +25 -0
  708. data/lib/lutaml/xml/schema/xsd/min_inclusive.rb +23 -0
  709. data/lib/lutaml/xml/schema/xsd/min_length.rb +25 -0
  710. data/lib/lutaml/xml/schema/xsd/namespace_mapping.rb +37 -0
  711. data/lib/lutaml/xml/schema/xsd/namespace_uri_remapping.rb +79 -0
  712. data/lib/lutaml/xml/schema/xsd/notation.rb +31 -0
  713. data/lib/lutaml/xml/schema/xsd/pattern.rb +25 -0
  714. data/lib/lutaml/xml/schema/xsd/redefine.rb +35 -0
  715. data/lib/lutaml/xml/schema/xsd/restriction_complex_content.rb +56 -0
  716. data/lib/lutaml/xml/schema/xsd/restriction_simple_content.rb +84 -0
  717. data/lib/lutaml/xml/schema/xsd/restriction_simple_type.rb +64 -0
  718. data/lib/lutaml/xml/schema/xsd/schema.rb +379 -0
  719. data/lib/lutaml/xml/schema/xsd/schema_file_validation_results.rb +55 -0
  720. data/lib/lutaml/xml/schema/xsd/schema_location_mapping.rb +74 -0
  721. data/lib/lutaml/xml/schema/xsd/schema_name_resolver.rb +32 -0
  722. data/lib/lutaml/xml/schema/xsd/schema_path.rb +207 -0
  723. data/lib/lutaml/xml/schema/xsd/schema_validator.rb +259 -0
  724. data/lib/lutaml/xml/schema/xsd/selector.rb +27 -0
  725. data/lib/lutaml/xml/schema/xsd/sequence.rb +68 -0
  726. data/lib/lutaml/xml/schema/xsd/serialized_schema.rb +185 -0
  727. data/lib/lutaml/xml/schema/xsd/simple_content.rb +61 -0
  728. data/lib/lutaml/xml/schema/xsd/simple_type.rb +37 -0
  729. data/lib/lutaml/xml/schema/xsd/total_digits.rb +29 -0
  730. data/lib/lutaml/xml/schema/xsd/type_index_entry.rb +40 -0
  731. data/lib/lutaml/xml/schema/xsd/type_resolution_result.rb +112 -0
  732. data/lib/lutaml/xml/schema/xsd/union.rb +30 -0
  733. data/lib/lutaml/xml/schema/xsd/unique.rb +31 -0
  734. data/lib/lutaml/xml/schema/xsd/validation_error.rb +48 -0
  735. data/lib/lutaml/xml/schema/xsd/validation_result.rb +86 -0
  736. data/lib/lutaml/xml/schema/xsd/version.rb +11 -0
  737. data/lib/lutaml/xml/schema/xsd/white_space.rb +27 -0
  738. data/lib/lutaml/xml/schema/xsd.rb +164 -0
  739. data/lib/lutaml/xml/schema/xsd_namespace.rb +29 -0
  740. data/lib/lutaml/xml/schema/xsd_schema.rb +1002 -0
  741. data/lib/lutaml/xml/schema.rb +16 -0
  742. data/lib/lutaml/xml/schema_location.rb +155 -0
  743. data/lib/lutaml/xml/serialization/collection_ext.rb +61 -0
  744. data/lib/lutaml/xml/serialization/format_conversion.rb +433 -0
  745. data/lib/lutaml/xml/serialization/instance_methods.rb +323 -0
  746. data/lib/lutaml/xml/serialization/model_import_ext.rb +40 -0
  747. data/lib/lutaml/xml/serialization.rb +15 -0
  748. data/lib/lutaml/xml/shared_dsl.rb +119 -0
  749. data/lib/lutaml/xml/transform.rb +6 -0
  750. data/lib/lutaml/xml/transformation/custom_method_wrapper.rb +258 -0
  751. data/lib/lutaml/xml/transformation/element_builder.rb +697 -0
  752. data/lib/lutaml/xml/transformation/order_reconciler.rb +282 -0
  753. data/lib/lutaml/xml/transformation/ordered_applier.rb +529 -0
  754. data/lib/lutaml/xml/transformation/rule_applier.rb +403 -0
  755. data/lib/lutaml/xml/transformation/rule_compiler.rb +556 -0
  756. data/lib/lutaml/xml/transformation/skip_logic.rb +70 -0
  757. data/lib/lutaml/xml/transformation/value_serializer.rb +137 -0
  758. data/lib/lutaml/xml/transformation.rb +454 -0
  759. data/lib/lutaml/xml/transformation_builder.rb +28 -0
  760. data/lib/lutaml/xml/transformation_support.rb +15 -0
  761. data/lib/lutaml/xml/type/configurable.rb +153 -0
  762. data/lib/lutaml/xml/type/serializers.rb +105 -0
  763. data/lib/lutaml/xml/type/value_xml_mapping.rb +94 -0
  764. data/lib/lutaml/xml/type_namespace/collector.rb +101 -0
  765. data/lib/lutaml/xml/type_namespace/declaration.rb +61 -0
  766. data/lib/lutaml/xml/type_namespace/planner.rb +121 -0
  767. data/lib/lutaml/xml/type_namespace/reference.rb +71 -0
  768. data/lib/lutaml/xml/type_namespace/resolver.rb +43 -0
  769. data/lib/lutaml/xml/type_namespace.rb +13 -0
  770. data/lib/lutaml/xml/type_namespace_resolver.rb +76 -0
  771. data/lib/lutaml/xml/unqualified_inheritance_strategy.rb +34 -0
  772. data/lib/lutaml/xml/w3c/registration.rb +66 -0
  773. data/lib/lutaml/xml/w3c.rb +398 -0
  774. data/lib/lutaml/xml/xml_attribute.rb +58 -0
  775. data/lib/lutaml/xml/xml_element.rb +498 -0
  776. data/lib/lutaml/xml/xml_namespace.rb +72 -0
  777. data/lib/lutaml/xml/xml_orderable.rb +17 -0
  778. data/lib/lutaml/xml/xsd_validator.rb +66 -0
  779. data/lib/lutaml/xml.rb +7 -0
  780. data/lib/lutaml/yaml/adapter/document.rb +12 -0
  781. data/lib/lutaml/yaml/adapter/mapping.rb +17 -0
  782. data/lib/lutaml/yaml/adapter/mapping_rule.rb +9 -0
  783. data/lib/lutaml/yaml/adapter/standard_adapter.rb +35 -0
  784. data/lib/lutaml/yaml/adapter/transform.rb +9 -0
  785. data/lib/lutaml/yaml/adapter/yeptris_adapter.rb +107 -0
  786. data/lib/lutaml/yaml/adapter.rb +18 -0
  787. data/lib/lutaml/yaml/format.rb +31 -0
  788. data/lib/lutaml/yaml/schema/yaml_schema.rb +65 -0
  789. data/lib/lutaml/yaml/schema.rb +9 -0
  790. data/lib/lutaml/yaml/type/serializers.rb +60 -0
  791. data/lib/lutaml/yaml.rb +7 -0
  792. data/lib/lutaml/yamlld/adapter.rb +20 -0
  793. data/lib/lutaml/yamlld.rb +25 -0
  794. data/lib/lutaml/yamls/adapter/document.rb +14 -0
  795. data/lib/lutaml/yamls/adapter/mapping.rb +30 -0
  796. data/lib/lutaml/yamls/adapter/mapping_rule.rb +9 -0
  797. data/lib/lutaml/yamls/adapter/standard_adapter.rb +56 -0
  798. data/lib/lutaml/yamls/adapter/transform.rb +124 -0
  799. data/lib/lutaml/yamls/adapter/yamls_sequence.rb +20 -0
  800. data/lib/lutaml/yamls/adapter/yamls_sequence_rule.rb +48 -0
  801. data/lib/lutaml/yamls/adapter.rb +15 -0
  802. data/lib/lutaml/yamls/format.rb +22 -0
  803. data/lib/lutaml/yamls.rb +7 -0
  804. data/lib/lutaml.rb +11 -5
  805. data/lib/tasks/benchmark_runner.rb +161 -0
  806. data/lib/tasks/memory_profile.rb +176 -0
  807. data/lib/tasks/performance.rake +80 -0
  808. data/lib/tasks/performance_benchmark.rb +499 -0
  809. data/lib/tasks/performance_comparator.rb +130 -0
  810. data/lib/tasks/performance_helpers.rb +149 -0
  811. data/lib/tasks/performance_probe.rake +33 -0
  812. data/lib/tasks/performance_probe.rb +106 -0
  813. data/lib/tasks/performance_probe_plan_walk.rb +58 -0
  814. data/lib/tasks/performance_probe_xml.rb +54 -0
  815. data/lib/tasks/xml_compiler_benchmark.rb +226 -0
  816. data/lib/tasks/xml_optimization_benchmark.rb +178 -0
  817. data/lutaml.gemspec +16 -8
  818. metadata +902 -83
  819. data/.github/workflows/docs.yml +0 -86
  820. data/.github/workflows/links.yml +0 -113
  821. data/.github/workflows/rake.yml +0 -23
  822. data/.github/workflows/release.yml +0 -37
  823. data/.gitignore +0 -29
  824. data/CLAUDE.md +0 -62
  825. data/docs/.github/workflows/docs.yml +0 -66
  826. data/docs/.github/workflows/links.yml +0 -78
  827. data/docs/CONTINUATION_PLAN.md +0 -168
  828. data/docs/Gemfile +0 -13
  829. data/docs/MIGRATION_GUIDE.md +0 -202
  830. data/docs/README.md +0 -252
  831. data/docs/REFACTOR_PLAN.md +0 -214
  832. data/docs/_config.yml +0 -144
  833. data/docs/_guides/cli-usage.adoc +0 -43
  834. data/docs/_guides/diagram-generation.adoc +0 -316
  835. data/docs/_guides/index.adoc +0 -136
  836. data/docs/_guides/parsing/express-parsing.adoc +0 -42
  837. data/docs/_guides/parsing/index.adoc +0 -78
  838. data/docs/_guides/parsing/qea-parsing.adoc +0 -47
  839. data/docs/_guides/parsing/xmi-parsing.adoc +0 -40
  840. data/docs/_guides/repository-management.adoc +0 -44
  841. data/docs/_guides/sysml-modeling.adoc +0 -37
  842. data/docs/_guides/uml-modeling.adoc +0 -115
  843. data/docs/_pages/concepts/diagram-generation.adoc +0 -337
  844. data/docs/_pages/concepts/lur-format.adoc +0 -711
  845. data/docs/_pages/concepts/qea-parsing.adoc +0 -418
  846. data/docs/_pages/concepts/uml-models.adoc +0 -43
  847. data/docs/_pages/core/architecture.adoc +0 -329
  848. data/docs/_pages/core/installation.adoc +0 -321
  849. data/docs/_pages/core/overview.adoc +0 -197
  850. data/docs/_pages/index.adoc +0 -49
  851. data/docs/_pages/uml-syntax.adoc +0 -1011
  852. data/docs/_references/api/parsers.adoc +0 -61
  853. data/docs/_references/api/presenters.adoc +0 -43
  854. data/docs/_references/api/repository.adoc +0 -67
  855. data/docs/_references/cli/commands.adoc +0 -72
  856. data/docs/_references/configuration/diagram-styles.adoc +0 -716
  857. data/docs/_references/configuration/index.adoc +0 -53
  858. data/docs/_references/configuration/package-metadata.adoc +0 -416
  859. data/docs/_references/formats/index.adoc +0 -43
  860. data/docs/_references/formats/lur-format.adoc +0 -39
  861. data/docs/_references/formats/lutaml-syntax.adoc +0 -379
  862. data/docs/_references/formats/qea-structure.adoc +0 -1364
  863. data/docs/_references/index.adoc +0 -198
  864. data/docs/_tutorials/documentation-site.adoc +0 -47
  865. data/docs/_tutorials/first-lur-package.adoc +0 -45
  866. data/docs/_tutorials/generating-diagrams.adoc +0 -42
  867. data/docs/_tutorials/getting-started.adoc +0 -45
  868. data/docs/_tutorials/index.adoc +0 -100
  869. data/docs/_tutorials/querying-models.adoc +0 -44
  870. data/docs/examples/build_package.rb +0 -12
  871. data/docs/examples/build_site.rb +0 -12
  872. data/docs/examples/city_model.rb +0 -21
  873. data/docs/examples/present_class.rb +0 -10
  874. data/docs/examples/query_model.rb +0 -12
  875. data/docs/examples/render_diagram.rb +0 -11
  876. data/docs/index.adoc +0 -64
  877. data/docs/lychee.toml +0 -50
  878. data/lib/lutaml/express/parsers/exp.rb +0 -28
  879. data/lib/lutaml/express.rb +0 -10
  880. data/scripts/check-site-urls.rb +0 -54
  881. data/scripts/check-vendor-link.py +0 -64
@@ -0,0 +1,1511 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Lutaml
4
+ module Model
5
+ class Attribute
6
+ attr_reader :name, :options
7
+
8
+ # Format scalars a mapped-model attribute may be handed in the
9
+ # key-value lanes (#978). Adapter element nodes and other object
10
+ # forms belong to the mapping lane and must not divert.
11
+ SCALAR_CAST_TYPES = [
12
+ ::String,
13
+ ::Numeric,
14
+ ::Symbol,
15
+ ::Time,
16
+ ::Date,
17
+ ::DateTime,
18
+ ::TrueClass,
19
+ ::FalseClass,
20
+ ].freeze
21
+
22
+ include CollectionHandler
23
+ include DeepDupable
24
+ include RestrictionValidation
25
+
26
+ # Symbol interpolation (:"to_#{format}") allocates a String and a
27
+ # Symbol per call on the serialization hot path; the table serves
28
+ # the known formats and the fallback keeps exotic ones working.
29
+ TO_FORMAT_METHODS = {
30
+ xml: :to_xml,
31
+ json: :to_json,
32
+ yaml: :to_yaml,
33
+ toml: :to_toml,
34
+ hash: :to_hash,
35
+ }.freeze
36
+
37
+ ALLOWED_OPTIONS = %i[
38
+ raw
39
+ default
40
+ delegate
41
+ collection
42
+ values
43
+ pattern
44
+ transform
45
+ choice
46
+ sequence
47
+ method
48
+ method_name
49
+ polymorphic
50
+ polymorphic_class
51
+ initialize_empty
52
+ validations
53
+ required
54
+ ref_model_class
55
+ ref_key_attribute
56
+ xsd_type
57
+ union_member_types
58
+ min
59
+ max
60
+ signed
61
+ min_length
62
+ max_length
63
+ desc
64
+ singular_tolerance
65
+ ].freeze
66
+
67
+ # Per-type-class memo of the custom from_xml/from_json probe used by #cast.
68
+ # Isolated cache holder: enclosing-class freezes (some suites freeze
69
+ # Lutaml::Model::Attribute) would freeze a constant Hash with it.
70
+ TypeProbeCache = ::Class.new do
71
+ class << self
72
+ def cache
73
+ @cache ||= {}
74
+ end
75
+ end
76
+ end
77
+
78
+ class << self
79
+ # Public reader for compiled rule plans: does this type class carry a
80
+ # custom from_xml/from_json (answer static, probed once)?
81
+ def custom_from_probe?(type)
82
+ cache = TypeProbeCache.cache
83
+ return cache[type] if cache.key?(type)
84
+
85
+ base = Lutaml::Model::Type::Value.singleton_class
86
+ cache[type] =
87
+ type.method(:from_xml).owner != base ||
88
+ type.method(:from_json).owner != base
89
+ end
90
+ end
91
+
92
+ MODEL_STRINGS = [
93
+ Lutaml::Model::Type::String,
94
+ "String",
95
+ :string,
96
+ ].freeze
97
+
98
+ # Delegate propagation to DeserializationContext for single source of truth.
99
+ CHILD_PROPAGATION_KEYS = Serialize::DeserializationContext::PROPAGATION_KEYS
100
+
101
+ # Methods where accidental override is likely to cause issues
102
+ # All names are allowed - this list only controls which ones get a warning
103
+ # Format-specific serialization methods (to_xml, to_json, etc.) are pushed
104
+ # by each format plugin at load time via format_specific_warn_names.
105
+ WARN_ON_OVERRIDE = %i[
106
+ # Ruby core - overriding breaks fundamental behavior
107
+ hash object_id class send method
108
+
109
+ # Object lifecycle - overriding without super breaks things
110
+ initialize
111
+
112
+ # Serialization methods - overriding breaks serialization
113
+ to_format
114
+
115
+ # Internal helpers - overriding breaks internal logic
116
+ attr_value attribute_exist? key_exist? key_value
117
+ using_default? using_default_for value_set_for
118
+ method_missing respond_to_missing?
119
+ ].freeze
120
+
121
+ # Format-specific warning names, appended at load time by format modules.
122
+ # Uses a class ivar instead of a constant since it's mutated at load time.
123
+ @format_specific_warn_names = []
124
+
125
+ def self.format_specific_warn_names
126
+ @format_specific_warn_names
127
+ end
128
+
129
+ def self.warn_on_override_names
130
+ WARN_ON_OVERRIDE + @format_specific_warn_names
131
+ end
132
+
133
+ def self.cast_type!(type)
134
+ case type
135
+ when Symbol then cast_from_symbol!(type)
136
+ when String then cast_from_string!(type)
137
+ when Class then type
138
+ else
139
+ raise ArgumentError, "Unknown Lutaml::Model::Type: #{type}"
140
+ end
141
+ end
142
+
143
+ def self.cast_from_symbol!(type)
144
+ Type.lookup(type)
145
+ rescue UnknownTypeError
146
+ raise ArgumentError, "Unknown Lutaml::Model::Type: #{type}"
147
+ end
148
+
149
+ def self.cast_from_string!(type)
150
+ Type.const_get(type)
151
+ rescue NameError
152
+ raise ArgumentError, "Unknown Lutaml::Model::Type: #{type}"
153
+ end
154
+
155
+ def initialize(name, type, options = {})
156
+ skip_validation = options.fetch(:skip_validation, false)
157
+
158
+ unless skip_validation
159
+ validate_name!(
160
+ name, reserved_methods: Lutaml::Model::Serializable.instance_methods
161
+ )
162
+ end
163
+
164
+ @name = name
165
+ @options = options.except(:skip_validation)
166
+
167
+ validate_presence!(type) unless skip_validation
168
+ @type = type
169
+ @unresolved_type = type
170
+ process_options! unless skip_validation
171
+ end
172
+
173
+ # Cache the resolver reference — GlobalContext.resolver is a singleton
174
+ # that never changes during the process lifetime. Avoids repeated
175
+ # singleton access overhead on every type() call.
176
+ def resolver
177
+ @resolver ||= GlobalContext.resolver
178
+ end
179
+
180
+ # The value-shaping policy for this attribute. Constructed lazily so
181
+ # the collection/union/ref flags are settled; memoized because they
182
+ # are fixed after definition.
183
+ def value_policy
184
+ @value_policy ||= ValuePolicy.new(
185
+ collection: collection?,
186
+ union: union?,
187
+ reference: !@options[:ref_model_class].nil?,
188
+ )
189
+ end
190
+
191
+ # Resolution that never materializes deferred model classes:
192
+ # raises UnknownTypeError for a not-yet-loaded class name.
193
+ # Mapping-time validation uses this so finalizing one mapping
194
+ # cannot fire an autoload that re-enters another model file
195
+ # mid-definition.
196
+ def loaded_type(context_or_register = nil)
197
+ return if unresolved_type.nil?
198
+
199
+ context = normalize_context(context_or_register)
200
+ resolver.resolve(unresolved_type, context, materialize: false)
201
+ end
202
+
203
+ def type(context_or_register = nil)
204
+ return if unresolved_type.nil?
205
+
206
+ # Performance: Fast path for nil or default register (most common case during deserialization)
207
+ if context_or_register.nil? || context_or_register == :default
208
+ return @cached_type_default ||= begin
209
+ context = normalize_context(context_or_register)
210
+ resolver.resolve(unresolved_type, context)
211
+ end
212
+ end
213
+
214
+ # Register/Symbol path: the resolution is a static fact of
215
+ # (attribute, register id), but the old code walked
216
+ # GlobalContext.context — a singleton hop, a delegation, a to_sym
217
+ # normalization and a registry lookup — on every call (2.4 M calls,
218
+ # 3.9 M GlobalContext#context hits per ISO-13849 parse). Cache keyed
219
+ # on the register id itself; a context replaced under the same id
220
+ # bumps GlobalContext.context_generation and flushes the cache.
221
+ register_id = case context_or_register
222
+ when Symbol
223
+ context_or_register
224
+ when Lutaml::Model::Register
225
+ context_or_register.id
226
+ end
227
+
228
+ if register_id
229
+ cache = (@type_cache_by_register ||= {})
230
+ generation = GlobalContext.context_generation
231
+ if @type_cache_generation != generation
232
+ cache.clear
233
+ @type_cache_generation = generation
234
+ end
235
+ cached = cache[register_id]
236
+ return cached if cached
237
+
238
+ context = GlobalContext.context(register_id)
239
+ # An unregistered id falls back to the (thread-local) default
240
+ # context — do not pin that answer in the shared cache.
241
+ return resolver.resolve(unresolved_type, context || GlobalContext.default_context) unless context
242
+
243
+ resolved = resolver.resolve(unresolved_type, context)
244
+ cache[register_id] = resolved
245
+ resolved
246
+ elsif context_or_register.is_a?(Lutaml::Model::TypeContext)
247
+ # Performance: Cache per TypeContext identity.
248
+ # When type substitution replaces a TypeContext, the object_id changes,
249
+ # so old cache entries are never hit again (safe invalidation).
250
+ cache_key = context_or_register.object_id
251
+ @type_cache ||= {}
252
+ cached = @type_cache[cache_key]
253
+ return cached if cached
254
+
255
+ resolved = resolver.resolve(unresolved_type, context_or_register)
256
+ @type_cache[cache_key] = resolved
257
+ resolved
258
+ else
259
+ @cached_type_default ||= begin
260
+ context = normalize_context(context_or_register)
261
+ resolver.resolve(unresolved_type, context)
262
+ end
263
+ end
264
+ end
265
+
266
+ # @api public
267
+ # Get type with namespace-aware resolution.
268
+ #
269
+ # Uses the register's resolve_in_namespace method for version-aware
270
+ # type resolution. Falls back to standard resolution if no namespace
271
+ # or register is provided.
272
+ #
273
+ # @param register [Lutaml::Model::Register, Symbol, nil] The register or register ID
274
+ # @param namespace_uri [String, nil] The namespace URI for version awareness
275
+ # @return [Class, nil] The type class or nil
276
+ def type_with_namespace(register, namespace_uri = nil)
277
+ return type(register) unless register && namespace_uri
278
+ return if unresolved_type.nil?
279
+
280
+ # Performance: Memoize type resolution per (register, namespace_uri) pair
281
+ # This avoids repeated resolve_in_namespace calls for the same attribute
282
+ @type_with_namespace_cache ||= {}
283
+ cache_key = [register, namespace_uri]
284
+ return @type_with_namespace_cache[cache_key] if @type_with_namespace_cache.key?(cache_key)
285
+
286
+ # Resolve register from symbol if needed
287
+ actual_register = if register.is_a?(Symbol)
288
+ Lutaml::Model::GlobalRegister.lookup(register)
289
+ else
290
+ register
291
+ end
292
+
293
+ # If we don't have an actual Register object, fall back to standard resolution
294
+ result = if actual_register.is_a?(Lutaml::Model::Register)
295
+ actual_register.resolve_in_namespace(unresolved_type,
296
+ namespace_uri)
297
+ end
298
+ result ||= type(register)
299
+
300
+ @type_with_namespace_cache[cache_key] = result
301
+ result
302
+ end
303
+
304
+ # Extract the Register from the context_or_register argument
305
+ def extract_register(_context_or_register)
306
+ # Register backward compatibility - now always returns nil
307
+ # Type resolution uses GlobalContext directly
308
+ nil
309
+ end
310
+
311
+ # Normalize register/context to TypeContext for resolution
312
+ # Performance: Optimized to reduce allocations in hot path
313
+ def normalize_context(context_or_register)
314
+ # Fast path for nil - most common case
315
+ return default_type_context if context_or_register.nil?
316
+
317
+ # Fast path for TypeContext - no conversion needed
318
+ return context_or_register if context_or_register.is_a?(Lutaml::Model::TypeContext)
319
+
320
+ # Handle Register and Symbol cases
321
+ context_id = case context_or_register
322
+ when Lutaml::Model::Register
323
+ context_or_register.id
324
+ when Symbol
325
+ context_or_register
326
+ else
327
+ return GlobalContext.default_context
328
+ end
329
+
330
+ GlobalContext.context(context_id) || GlobalContext.default_context
331
+ end
332
+
333
+ # Performance: Cache default type context lookup
334
+ def default_type_context
335
+ @default_type_context ||= begin
336
+ default_id = Lutaml::Model::Config.default_register
337
+ ctx = GlobalContext.context(default_id)
338
+ ctx || GlobalContext.default_context
339
+ end
340
+ end
341
+
342
+ def unresolved_type
343
+ @unresolved_type || @type
344
+ end
345
+
346
+ def reference_type?
347
+ (@reference_type ||= unresolved_type == Lutaml::Model::Type::Reference)
348
+ end
349
+
350
+ def value_map_boolean?
351
+ (@value_map_boolean ||=
352
+ type == Lutaml::Model::Type::Boolean ||
353
+ unresolved_type == Lutaml::Model::Type::Boolean)
354
+ end
355
+
356
+ def polymorphic?
357
+ @options[:polymorphic_class]
358
+ end
359
+
360
+ def union?
361
+ return @union unless @union.nil?
362
+
363
+ @union = unresolved_type == Lutaml::Model::Type::Union
364
+ end
365
+
366
+ def union_member_types
367
+ @union_member_types ||=
368
+ @options[:union_member_types].map { |member| cast_type!(member) }
369
+ end
370
+
371
+ def derived?
372
+ !method_name.nil?
373
+ end
374
+
375
+ def delegate
376
+ @options[:delegate]
377
+ end
378
+
379
+ # Performance: Frozen empty hash to reduce allocations
380
+ EMPTY_TRANSFORM_HASH = {}.freeze
381
+
382
+ # Default-argument options for the serialize lane. The per-call
383
+ # `options = {}` literal allocated one Hash per serialize call
384
+ # (two per mapped XML row); every consumer of the argument only
385
+ # reads it or derives a new hash (merge), so a shared frozen
386
+ # empty is safe.
387
+ EMPTY_OPTIONS = {}.freeze
388
+
389
+ def transform
390
+ # Options are fixed after definition (value_policy memoizes the
391
+ # same way) — the per-call @options[:transform] Hash#[] was hit
392
+ # 2.9 M times on the ISO-13849 parse profile.
393
+ @transform ||= @options[:transform] || EMPTY_TRANSFORM_HASH
394
+ end
395
+
396
+ def method_name
397
+ @options[:method_name]
398
+ end
399
+
400
+ def initialize_empty?
401
+ @options[:initialize_empty]
402
+ end
403
+
404
+ # True when the default is the empty-collection lambda installed by
405
+ # set_default_for_collection: the one default whose constructor
406
+ # state (a plain empty Array) the LAZY_EMPTY_COLLECTION sentinel
407
+ # materializes to on first read, so walk-state seeding can use the
408
+ # sentinel instead of running the lambda per instance (#1010).
409
+ # Restricted to plain-Array collections because the lazy reader
410
+ # materializes []; custom Collection classes would lose their type.
411
+ def lazy_collection_default?
412
+ @implicit_collection_default == true && collection? &&
413
+ collection_class == ::Array && !enum?
414
+ end
415
+
416
+ def validations
417
+ @options[:validations]
418
+ end
419
+
420
+ def cast_type!(type)
421
+ self.class.cast_type!(type)
422
+ end
423
+
424
+ # Per-(attribute, register) memo for the dominant scalar case: the
425
+ # resolved type is a plain Type::Value with no custom probes, the
426
+ # attribute is not a collection/union/reference, and the input is a
427
+ # String (the shape every wire format hands over). The full cast
428
+ # chain resolves the same type and lands on the same
429
+ # `resolved_type.cast(value)` call — this skips the eight
430
+ # intermediate checks per value. Generation-guarded like
431
+ # #type's register cache: a replaced register context flushes it.
432
+ def fast_scalar_type(register)
433
+ generation = GlobalContext.context_generation
434
+ cache = (@fast_scalar_types ||= {}.compare_by_identity)
435
+ if @fast_scalar_generation != generation
436
+ cache.clear
437
+ @fast_scalar_generation = generation
438
+ end
439
+
440
+ cache[register] ||= begin
441
+ resolved = type(register)
442
+ resolved if resolved.is_a?(Class) &&
443
+ resolved < Lutaml::Model::Type::Value &&
444
+ resolved != Lutaml::Model::Type::Hash &&
445
+ !union? && !collection? && @options[:ref_model_class].nil? &&
446
+ !self.class.custom_from_probe?(resolved)
447
+ end
448
+ end
449
+
450
+ def cast_value(value, register)
451
+ if value.is_a?(::String) && (fast = fast_scalar_type(register))
452
+ return fast.cast(value)
453
+ end
454
+
455
+ if list_like?(value)
456
+ items = cast_items(value, register)
457
+ elsif coerce_to_collection?(value)
458
+ items = cast_items([value], register)
459
+ else
460
+ return cast_element(value, register)
461
+ end
462
+ # cast_items already returns a fresh array, so the plain-Array
463
+ # collection needs no re-wrap — build_collection's
464
+ # collection_class.new would copy it again.
465
+ assert_flat_collection_items!(items)
466
+ return items if !custom_collection? && collection_class == ::Array
467
+
468
+ build_collection(items, register: register)
469
+ end
470
+
471
+ # Fail loudly on nested arrays. A collection's declared element
472
+ # type never admits an Array as an item; the legacy
473
+ # build_collection flatten silently absorbed mis-spliced builder
474
+ # output (expressir#506 surfaced it three frames away in a
475
+ # formatter). The error must land at the assignment boundary.
476
+ def assert_flat_collection_items!(items)
477
+ return unless items.any?(::Array)
478
+
479
+ raise TypeError,
480
+ "collection '#{name}': item " \
481
+ "#{items.index { |item| item.is_a?(::Array) }} is an Array " \
482
+ "where the declared element type is expected; nested arrays " \
483
+ "are not flattened — splice list results before assignment"
484
+ end
485
+
486
+ # Plain Arrays count as list input. On singular attributes
487
+ # collection_instance? matches Arrays too (their collection class is
488
+ # Array), preserving the Array so strict cardinality can flag it.
489
+ def list_like?(value)
490
+ collection_instance?(value) || (collection? && value.is_a?(::Array))
491
+ end
492
+
493
+ # Prepare the seed items for a collection. Custom Collection classes
494
+ # cast their own items (idempotently) in #initialize, so hand them a
495
+ # plain array of the existing elements — rebuilding a fresh collection
496
+ # avoids sharing a mutable default across instances. Plain collections
497
+ # cast each element here.
498
+ def cast_items(value, register)
499
+ return value.to_a if custom_collection?
500
+
501
+ value.map { |v| cast_element(v, register) }
502
+ end
503
+
504
+ # Cast the value a derived reader just recomputed.
505
+ #
506
+ # A derived attribute has no ivar and no writer. Its reader runs the
507
+ # source method and casts the result on every call, which makes the
508
+ # reader a casting entry point of its own — nothing a writer-side guard
509
+ # can reach. A collection still has to come back as a collection here,
510
+ # even when the source method returned nothing.
511
+ #
512
+ # @param value [Object] whatever the source method returned
513
+ # @param register [Symbol] register for type resolution
514
+ # @return [Object] the cast value, or an empty collection
515
+ def cast_derived(value, register)
516
+ return cast_element(value, register) unless collection?
517
+ return build_collection if no_data?(value)
518
+ return cast_value(value, register) if collection_instance?(value)
519
+ # A plain Array is a list of source elements even when the attribute
520
+ # declares its own collection class, which collection_instance? only
521
+ # recognises by that class. Without this it becomes one element whose
522
+ # value is the inspected Array.
523
+ if value.is_a?(::Array)
524
+ return build_collection(value.map { |v| cast_element(v, register) })
525
+ end
526
+
527
+ build_collection(cast_element(value, register))
528
+ end
529
+
530
+ # Apply a value map to transform a value.
531
+ #
532
+ # value_map keys (:nil, :empty, :omitted) each map either to a symbolic
533
+ # option (:nil, :empty, :omitted) or, for Boolean attributes, directly
534
+ # to true/false. The nested form value_map[:from][key] = true/false is
535
+ # accepted unconditionally; the bare form value_map[key] = true/false
536
+ # is gated on the attribute being a Boolean type.
537
+ def apply_value_map(value, value_map)
538
+ key = if value.nil? then :nil
539
+ elsif Utils.empty?(value) then :empty
540
+ elsif Utils.uninitialized?(value) then :omitted
541
+ end
542
+ return value unless key
543
+
544
+ nested = value_map.dig(:from, key)
545
+ return nested if nested.is_a?(TrueClass) || nested.is_a?(FalseClass)
546
+
547
+ option = value_map[key]
548
+ if (option.is_a?(TrueClass) || option.is_a?(FalseClass)) &&
549
+ value_map_boolean?
550
+ return option
551
+ end
552
+
553
+ case option
554
+ when :nil
555
+ nil
556
+ when :empty
557
+ if key == :empty then value
558
+ elsif collection? then build_collection
559
+ else ""
560
+ end
561
+ else
562
+ Lutaml::Model::UninitializedClass.instance
563
+ end
564
+ end
565
+
566
+ def required_value_set?(value)
567
+ return true unless options[:required]
568
+ return false if value.nil?
569
+ return false if Utils.empty?(value)
570
+
571
+ true
572
+ end
573
+
574
+ # True when the value is "nothing arrived" rather than data.
575
+ #
576
+ # nil and the uninitialized sentinel both mean the source carried no
577
+ # value. Neither is something a type can be asked to turn into an
578
+ # instance.
579
+ #
580
+ # @param value [Object]
581
+ # @return [Boolean]
582
+ def no_data?(value)
583
+ value.nil? || Utils.uninitialized?(value)
584
+ end
585
+
586
+ def cast_element(value, register)
587
+ # Resolve first: an undeclared type has to raise UnknownTypeError
588
+ # even for a nil value (the 0.8.33 behavior).
589
+ resolved_type = type(register)
590
+
591
+ return value if Utils.uninitialized?(value)
592
+
593
+ # nil reaches the type's cast — the long-shipped contract
594
+ # ST_OnOff-style types depend on (absent attribute -> cast(nil)
595
+ # -> false; lutaml-model#795). What nil must NOT do is
596
+ # manufacture a typed INSTANCE from nothing: that is the
597
+ # phantom #793 removed, suppressed by the post-check below.
598
+ if value.nil?
599
+ result = cast_element_present(value, register, resolved_type)
600
+ return result if result.nil?
601
+ return nil if result.is_a?(Lutaml::Model::Type::Value) ||
602
+ result.is_a?(Lutaml::Model::Serialize)
603
+
604
+ return result
605
+ end
606
+
607
+ cast_element_present(value, register, resolved_type)
608
+ end
609
+
610
+ def cast_element_present(value, register, resolved_type = nil)
611
+ resolved_type ||= type(register)
612
+
613
+ return cast_union(value, nil, register) if union?
614
+ return resolved_type.new(value) if value.is_a?(::Hash) && !hash_type?
615
+
616
+ # Special handling for Reference types - pass the metadata
617
+ # (the comparison is attribute-constant; memoize the verdict)
618
+ if reference_type?
619
+ return resolved_type.cast_with_metadata(value,
620
+ @options[:ref_model_class], @options[:ref_key_attribute])
621
+ end
622
+
623
+ # The castability verdict is a class-hierarchy fact, immutable
624
+ # per resolved type — check once, not per value (TODO.max-perf/15).
625
+ checked = (@castable_types ||= {}.compare_by_identity)
626
+ unless checked[resolved_type]
627
+ validate_attr_type!(resolved_type)
628
+ checked[resolved_type] = true
629
+ end
630
+
631
+ resolved_type.cast(value)
632
+ end
633
+
634
+ def hash_type?
635
+ type == Lutaml::Model::Type::Hash
636
+ end
637
+
638
+ def setter
639
+ :"#{@name}="
640
+ end
641
+
642
+ # Collection methods are provided by CollectionHandler module
643
+
644
+ def raw?
645
+ @raw
646
+ end
647
+
648
+ def enum?
649
+ !enum_values.empty?
650
+ end
651
+
652
+ def default(register = Lutaml::Model::Config.default_register,
653
+ instance_object = nil)
654
+ if instance_object.nil?
655
+ @default_cache ||= {}
656
+ cached = @default_cache[register]
657
+ return cached if cached
658
+
659
+ result = cast_value(default_value(register, nil), register)
660
+ if immutable_value?(result)
661
+ @default_cache[register] = result
662
+ end
663
+ result
664
+ else
665
+ cast_value(default_value(register, instance_object), register)
666
+ end
667
+ end
668
+
669
+ def immutable_value?(value)
670
+ value.nil? || value.is_a?(Numeric) || value.is_a?(String) ||
671
+ value.is_a?(Symbol) || value == true || value == false ||
672
+ value.equal?(::Lutaml::Model::UninitializedClass.instance) ||
673
+ value.frozen?
674
+ end
675
+
676
+ # Static classification of this attribute's default form (:none,
677
+ # :static, :proc, :delegate) — the constructor's determine_value
678
+ # and the compiled walk-seed share it.
679
+ def default_kind
680
+ @default_kind ||= _default_kind
681
+ end
682
+
683
+ def default_value(register, instance_object = nil)
684
+ # The kind is fixed at definition; the common case (no default
685
+ # at all) paid three option checks per absent attribute per
686
+ # instantiation before the memo.
687
+ case (@default_kind ||= _default_kind)
688
+ when :none
689
+ Lutaml::Model::UninitializedClass.instance
690
+ when :static
691
+ options[:default]
692
+ when :proc
693
+ if instance_object
694
+ ::Lutaml::Model::Attribute.evaluating_default do
695
+ instance_object.instance_exec(&options[:default])
696
+ end
697
+ else
698
+ options[:default].call
699
+ end
700
+ else # :delegate
701
+ type(register).attributes(register)[to].default(register,
702
+ instance_object)
703
+ end
704
+ end
705
+
706
+ def _default_kind
707
+ return :delegate if delegate
708
+ return :proc if options[:default].is_a?(Proc)
709
+ return :static if options.key?(:default)
710
+
711
+ :none
712
+ end
713
+
714
+ # Marks the dynamic extent in which a default proc runs against a
715
+ # model instance, so Serialize#method_missing can fall back to the
716
+ # model class for methods the instance does not define (0.7.x
717
+ # compatibility, lutaml-model#745).
718
+ def self.evaluating_default
719
+ previous = Thread.current[:__lutaml_evaluating_default]
720
+ Thread.current[:__lutaml_evaluating_default] = true
721
+ yield
722
+ ensure
723
+ Thread.current[:__lutaml_evaluating_default] = previous
724
+ end
725
+
726
+ def self.default_evaluation?
727
+ Thread.current[:__lutaml_evaluating_default] == true
728
+ end
729
+
730
+ def default_set?(register, instance_object = nil)
731
+ !Utils.uninitialized?(default_value(register, instance_object))
732
+ end
733
+
734
+ def pattern
735
+ options[:pattern]
736
+ end
737
+
738
+ # Documentation metadata (#356): the `:desc` attribute option,
739
+ # consumed by documentation and schema tooling.
740
+ def desc
741
+ options[:desc]
742
+ end
743
+
744
+ # Performance: Frozen empty array to reduce allocations
745
+ EMPTY_VALUES_ARRAY = [].freeze
746
+
747
+ def enum_values
748
+ @options.key?(:values) ? @options[:values] : EMPTY_VALUES_ARRAY
749
+ end
750
+
751
+ def transform_import_method
752
+ transform[:import]
753
+ end
754
+
755
+ def transform_export_method
756
+ transform[:export]
757
+ end
758
+
759
+ def valid_value!(value)
760
+ # nil is never tested against the value set, whether it arrives as the
761
+ # whole value or as one element of a collection (this method recurses
762
+ # per element). valid_pattern! skips nil the same way, and an unset
763
+ # attribute is validate_required!'s business, not the enum's.
764
+ return true if value.nil?
765
+ return true unless enum?
766
+ return true if Utils.uninitialized?(value)
767
+
768
+ # Collection attributes hold multiple values; validate each element
769
+ # against the allowed set rather than the coerced collection itself.
770
+ if value.is_a?(::Array) || collection_instance?(value)
771
+ return value.all? { |v| valid_value!(v) }
772
+ end
773
+
774
+ unless valid_value?(value)
775
+ raise Lutaml::Model::InvalidValueError.new(name, value, enum_values)
776
+ end
777
+
778
+ true
779
+ end
780
+
781
+ def valid_value?(value)
782
+ return true unless options[:values]
783
+
784
+ options[:values].include?(value)
785
+ end
786
+
787
+ # Pattern binds actual string values only. For a plain :string attribute
788
+ # every element is a string; for a union the pattern applies to whichever
789
+ # elements took the :string branch (non-string members are exempt). A nil
790
+ # element is skipped along with every other non-string, and Array(value)
791
+ # flattens both plain Arrays and custom Collections so the pattern applies
792
+ # per element instead of to the collection as a whole.
793
+ def valid_pattern!(value, _resolved_type)
794
+ return true unless pattern
795
+
796
+ Array(value).each do |item|
797
+ next unless item.is_a?(::String)
798
+ next if pattern.match?(item)
799
+
800
+ raise Lutaml::Model::PatternNotMatchedError.new(name, pattern, item)
801
+ end
802
+
803
+ true
804
+ end
805
+
806
+ # Check if the value to be assigned is valid for the attribute
807
+ #
808
+ # Currently there are 2 validations
809
+ # 1. Value should be from the values list if they are defined
810
+ # e.g values: ["foo", "bar"] is set then any other value for this
811
+ # attribute will raise `Lutaml::Model::InvalidValueError`
812
+ #
813
+ # 2. Value count should be between the collection range if defined
814
+ # e.g if collection: 0..5 is set then the value greater then 5
815
+ # will raise `Lutaml::Model::CollectionCountOutOfRangeError`
816
+ def validate_value!(value, register, instance_object: nil)
817
+ # Use the default value if the value is nil
818
+ validate_required!(value)
819
+
820
+ if value.nil?
821
+ value = cast_value(default_value(register, instance_object),
822
+ register)
823
+ end
824
+ resolved_type = type(register)
825
+ validate_restriction_configuration!(resolved_type)
826
+
827
+ # Shape before contents. An over-count is a cardinality violation, not
828
+ # an enum or pattern one, and checking it first keeps those predicates
829
+ # from reporting on a value whose shape is already wrong.
830
+ valid_collection!(value, instance_object&.class) &&
831
+ valid_value!(value) &&
832
+ valid_pattern!(value, resolved_type) &&
833
+ validate_polymorphic!(value, resolved_type) &&
834
+ execute_validations!(value)
835
+
836
+ validate_restriction_values!(value, resolved_type)
837
+ end
838
+
839
+ # execute custom validations on the attribute value
840
+ # i.e presence: true, numericality: true, etc
841
+ def execute_validations!(value)
842
+ return true if Utils.blank?(value)
843
+
844
+ memoization_container = {}
845
+ errors = Lutaml::Model::Validator.call(value, validations,
846
+ memoization_container)
847
+
848
+ return if errors.empty?
849
+
850
+ raise Lutaml::Model::ValidationFailedError.new(errors)
851
+ end
852
+
853
+ def validate_polymorphic(value, resolved_type)
854
+ if value.is_a?(Array)
855
+ return value.all? do |v|
856
+ validate_polymorphic!(v, resolved_type)
857
+ end
858
+ end
859
+ return true unless options[:polymorphic]
860
+
861
+ valid_polymorphic_type?(value, resolved_type)
862
+ end
863
+
864
+ def validate_polymorphic!(value, resolved_type)
865
+ return true if validate_polymorphic(value, resolved_type)
866
+
867
+ raise Lutaml::Model::PolymorphicError.new(value, options, resolved_type)
868
+ end
869
+
870
+ def validate_collection_range
871
+ range = @options[:collection]
872
+ return if range == true
873
+ return if custom_collection?
874
+
875
+ unless range.is_a?(Range)
876
+ raise ArgumentError, "Invalid collection range: #{range}"
877
+ end
878
+
879
+ validate_range!(range)
880
+ end
881
+
882
+ def validate_range!(range)
883
+ if range.begin.nil?
884
+ raise ArgumentError,
885
+ "Invalid collection range: #{range}. Begin must be specified."
886
+ end
887
+
888
+ if range.begin.negative?
889
+ raise ArgumentError,
890
+ "Invalid collection range: #{range}. " \
891
+ "Begin must be non-negative."
892
+ end
893
+
894
+ if range.end && range.end < range.begin
895
+ raise ArgumentError,
896
+ "Invalid collection range: #{range}. " \
897
+ "End must be greater than or equal to begin."
898
+ end
899
+ end
900
+
901
+ # Singular-overflow tolerance (#971): ingest can hand a singular
902
+ # attribute a collection — relaton's upstream documents carry
903
+ # multiple <formattedref> elements per bibitem. With
904
+ # singular_tolerance: :first the leading value is kept instead of
905
+ # raising CollectionTrueMissingError; the default stays strict.
906
+ def tolerates_singular_overflow?(value)
907
+ !collection? && @options[:singular_tolerance] == :first &&
908
+ collection_instance?(value) &&
909
+ !value_policy.whole_value?(unresolved_type)
910
+ end
911
+
912
+ def valid_collection!(value, caller)
913
+ if collection_instance?(value) && !collection? &&
914
+ !value_policy.whole_value?(unresolved_type)
915
+ raise Lutaml::Model::CollectionTrueMissingError.new(name,
916
+ caller)
917
+ end
918
+
919
+ return true unless collection?
920
+
921
+ # Allow any value for unbounded collections
922
+ return true if collection == true
923
+
924
+ unless collection_instance?(value)
925
+ # An absent value satisfies a zero minimum and has nothing to size.
926
+ return true if (value.nil? || Utils.uninitialized?(value)) &&
927
+ resolved_collection.min.zero?
928
+
929
+ raise Lutaml::Model::CollectionCountOutOfRangeError.new(
930
+ name,
931
+ value,
932
+ collection,
933
+ )
934
+ end
935
+
936
+ # cover? rather than between?, so an exclusive range such as (0...5)
937
+ # rejects a count of 5.
938
+ in_range = if resolved_collection.end.infinite?
939
+ value.size >= resolved_collection.begin
940
+ else
941
+ resolved_collection.cover?(value.size)
942
+ end
943
+
944
+ unless in_range
945
+ raise Lutaml::Model::CollectionCountOutOfRangeError.new(
946
+ name,
947
+ value,
948
+ collection,
949
+ )
950
+ end
951
+
952
+ # Truthy on success: validate_value! chains this with && before the
953
+ # value/pattern/polymorphic/custom checks, so falling through as nil would
954
+ # silently skip them for a valid bounded-range collection.
955
+ true
956
+ end
957
+
958
+ def serialize(value, format, register, options = EMPTY_OPTIONS)
959
+ value ||= build_collection if collection? && initialize_empty?
960
+ return value if value.nil? || Utils.uninitialized?(value)
961
+
962
+ resolved_type = options[:resolved_type] || type(register)
963
+ value = reference_key(value) if unresolved_type == Lutaml::Model::Type::Reference
964
+ if collection_instance?(value)
965
+ return serialize_array(value, format, register,
966
+ options.merge(resolved_type: resolved_type))
967
+ end
968
+ if resolved_type <= Serialize
969
+ return serialize_model(value, format, register,
970
+ options)
971
+ end
972
+
973
+ serialize_value(value, format, resolved_type)
974
+ end
975
+
976
+ def reference_key(value)
977
+ return nil unless value
978
+ return value.map { |item| reference_key(item) } if value.is_a?(Array)
979
+
980
+ return value.public_send(@options[:ref_key_attribute]) if model_instance?(value)
981
+
982
+ value
983
+ end
984
+
985
+ def model_instance?(value)
986
+ return false unless @options[:ref_model_class]
987
+
988
+ value.class.name == @options[:ref_model_class]
989
+ end
990
+
991
+ def cast(value, format, register, options = {})
992
+ # Sentinel: never a cast input. nil flows on — absent values
993
+ # reach the type's cast (ST_OnOff booleans, #795); a cast that
994
+ # manufactures a typed instance from nothing is the phantom
995
+ # #793 removed, suppressed here as in cast_element.
996
+ return value if Utils.uninitialized?(value)
997
+
998
+ if value.nil?
999
+ result = cast_present(value, format, register, options)
1000
+ return result if result.nil?
1001
+ return nil if result.is_a?(Lutaml::Model::Type::Value) ||
1002
+ result.is_a?(Lutaml::Model::Serialize)
1003
+
1004
+ return result
1005
+ end
1006
+
1007
+ cast_present(value, format, register, options)
1008
+ end
1009
+
1010
+ def cast_present(value, format, register, options = {})
1011
+ # Namespace-aware type resolution: use type_with_namespace if namespace_uri provided
1012
+ namespace_uri = options[:namespace_uri]
1013
+ resolved_type = if options[:resolved_type]
1014
+ options[:resolved_type]
1015
+ elsif register && namespace_uri
1016
+ type_with_namespace(register, namespace_uri)
1017
+ else
1018
+ type(register)
1019
+ end
1020
+ if (collection_instance?(value) || value.is_a?(Array)) &&
1021
+ !value_policy.whole_value?(resolved_type)
1022
+ merged_opts = options.merge(resolved_type: resolved_type,
1023
+ converted: true)
1024
+ return build_collection(value.map do |v|
1025
+ cast(v, format, register, merged_opts)
1026
+ end, register: register)
1027
+ end
1028
+
1029
+ return value if already_serialized?(resolved_type, value)
1030
+
1031
+ return cast_union(value, format, register) if union?
1032
+
1033
+ # Special handling for Reference types - pass the metadata
1034
+ # Check @options[:ref_model_class] which is set when type is { ref: [...] }
1035
+ if @options[:ref_model_class] && resolved_type == Lutaml::Model::Type::Reference
1036
+ return resolved_type.cast_with_metadata(value,
1037
+ @options[:ref_model_class], @options[:ref_key_attribute])
1038
+ end
1039
+
1040
+ # Fast path for Type::Value subclasses (String, Integer, Boolean, etc.)
1041
+ # These are never Serializable, so skip expensive can_serialize? and needs_conversion? checks
1042
+ # Skip if type has custom from_xml/from_json methods (defined on the class itself, not inherited).
1043
+ # The probe allocated two Method objects per cast call; the answer is
1044
+ # static per type class, so it is resolved once.
1045
+ if resolved_type.is_a?(Class) && resolved_type < Lutaml::Model::Type::Value && !self.class.custom_from_probe?(resolved_type)
1046
+ return resolved_type.cast(value)
1047
+ end
1048
+
1049
+ klass = resolve_polymorphic_class(resolved_type, value, options)
1050
+ # A scalar handed to a mapped-model attribute crashed
1051
+ # apply_mappings with an internal NoMethodError (key? on
1052
+ # String, #978). A type declaring its own .cast owns scalar
1053
+ # construction; base-cast identity types fall through to the
1054
+ # legacy conversion chain, whose parse error names the token.
1055
+ # Non-scalar input (adapter elements, hashes, arrays) rides
1056
+ # the mapping lane untouched.
1057
+ if serializable_type?(register) && !value.nil? &&
1058
+ SCALAR_CAST_TYPES.any? { |type| value.is_a?(type) } &&
1059
+ klass.respond_to?(:cast) &&
1060
+ klass.method(:cast).owner == klass.singleton_class
1061
+ casted = klass.cast(value)
1062
+ return casted if casted.is_a?(klass)
1063
+
1064
+ raise Lutaml::Model::IncorrectModelError,
1065
+ "attribute '#{name}': the #{format} input for type " \
1066
+ "#{klass} is a #{value.class}, and #{klass}.cast did " \
1067
+ "not build one (received #{casted.class})"
1068
+ end
1069
+
1070
+ if can_serialize?(klass, value, format, options)
1071
+ propagated = Serialize::DeserializationContext.propagate(options)
1072
+ klass.apply_mappings(value, format,
1073
+ propagated.merge(register: register))
1074
+ elsif needs_conversion?(klass, value)
1075
+ klass.public_send(:"from_#{format}", value)
1076
+ else
1077
+ # No need to use register#get_class,
1078
+ # can_serialize? method already checks if type is Serializable or not.
1079
+ Type.lookup(klass).cast(value)
1080
+ end
1081
+ end
1082
+
1083
+ def serializable?(register)
1084
+ type(register) <= Serialize
1085
+ end
1086
+
1087
+ # Cached version of serializable? check for hot deserialization path
1088
+ # Called millions of times in resolve_rule_names_with_type and value_for_rule
1089
+ def serializable_type?(register = nil)
1090
+ register_key = register || :default
1091
+ return @serializable_type_cache[register_key] if defined?(@serializable_type_cache) && @serializable_type_cache&.key?(register_key)
1092
+
1093
+ resolved_type = type(register_key)
1094
+ result = resolved_type.is_a?(Class) && resolved_type.include?(Serialize)
1095
+ @serializable_type_cache ||= {}
1096
+ @serializable_type_cache[register_key] = result
1097
+ end
1098
+
1099
+ # resolved_collection is provided by CollectionHandler module
1100
+
1101
+ def sequenced_appearance_count(element_order, mapped_name, current_index)
1102
+ elements = element_order[current_index..]
1103
+ element_count = elements.take_while do |element|
1104
+ element == mapped_name
1105
+ end.count
1106
+ return element_count if element_count.between?(*resolved_collection.minmax)
1107
+
1108
+ raise Lutaml::Model::ElementCountOutOfRangeError.new(
1109
+ mapped_name,
1110
+ element_count,
1111
+ collection,
1112
+ )
1113
+ end
1114
+
1115
+ def validate_choice_content!(elements)
1116
+ return elements.count unless resolved_collection
1117
+ return 1 if elements.count.between?(*resolved_collection.minmax)
1118
+
1119
+ elements.each_slice(resolved_collection.max).count
1120
+ end
1121
+
1122
+ # min_collection_zero? is provided by CollectionHandler module
1123
+
1124
+ def choice
1125
+ @options[:choice]
1126
+ end
1127
+
1128
+ def process_options!
1129
+ validate_options!(@options)
1130
+ if union?
1131
+ @options[:union_member_types] =
1132
+ Lutaml::Model::Type::Union.validate_members!(@options[:union_member_types])
1133
+ Lutaml::Model::Type::Union.validate_combo!(@options)
1134
+ end
1135
+ # `restrict` merges new options into the SAME attribute object
1136
+ # post-construction — the option-derived memos must reset here or
1137
+ # collection?/transform keep answering from the pre-restrict state.
1138
+ remove_instance_variable(:@collection_option) if defined?(@collection_option)
1139
+ remove_instance_variable(:@transform) if defined?(@transform)
1140
+ @raw = !!@options[:raw]
1141
+ if @raw
1142
+ warn "[DEPRECATED] attribute :#{name}, :string, raw: true is deprecated. " \
1143
+ "Use map_element \"name\", to: :#{name}, raw: :content instead."
1144
+ end
1145
+ @validations = @options[:validations]
1146
+ tolerance = @options[:singular_tolerance]
1147
+ unless tolerance.nil? || tolerance == :first
1148
+ raise ArgumentError,
1149
+ "Invalid singular_tolerance: #{tolerance.inspect} for " \
1150
+ "attribute '#{name}'. Supported: :first"
1151
+ end
1152
+ set_default_for_collection if collection?
1153
+ end
1154
+
1155
+ def deep_dup
1156
+ # Don't deep_dup the entire options hash because:
1157
+ # 1. Lambdas/Procs (like :default) should not be duplicated
1158
+ # 2. Classes (like :collection class) are immutable
1159
+ # 3. Deep dupping creates circular references when lambdas close over the attribute
1160
+
1161
+ # Selectively copy options using direct type checks to avoid method calls
1162
+ duped_options = { skip_validation: true }
1163
+ options.each do |key, value|
1164
+ duped_options[key] = case value
1165
+ when Symbol, TrueClass, FalseClass, Numeric, Class, Module, Proc, Method, NilClass
1166
+ value # Immutable, don't dup
1167
+ when Range
1168
+ # Only dup if bounds are mutable strings
1169
+ if value.begin.is_a?(String) || (value.end && value.end.is_a?(String))
1170
+ Range.new(value.begin.dup, value.end&.dup, value.exclude_end?)
1171
+ else
1172
+ value # Immutable bounds, safe to reuse
1173
+ end
1174
+ when Hash
1175
+ Utils.deep_dup(value)
1176
+ when Array
1177
+ Utils.deep_dup(value)
1178
+ else
1179
+ value # Keep as-is (might be a complex object)
1180
+ end
1181
+ end
1182
+
1183
+ # Skip validation during deep_dup - options are already validated in original
1184
+ # This prevents infinite recursion when process_options! tries to access collection
1185
+ self.class.new(name, unresolved_type, duped_options).tap do |dup_attr|
1186
+ dup_attr.copy_internal_state_from(self)
1187
+ end
1188
+ end
1189
+
1190
+ # @api public
1191
+ # Get namespace class from Type::Value or Model class
1192
+ #
1193
+ # @param register [Symbol, nil] register ID for type resolution
1194
+ # @return [Class, nil] XmlNamespace class if type has namespace
1195
+ def type_namespace_class(register = nil)
1196
+ register_key = register || :default
1197
+ return @type_ns_class_cache[register_key] if defined?(@type_ns_class_cache) && @type_ns_class_cache&.key?(register_key)
1198
+
1199
+ # Resolve type namespace via type() which uses GlobalContext.resolver
1200
+ resolved_type = type(register_key)
1201
+ result = nil
1202
+
1203
+ # Check if type is a Type::Value class
1204
+ # Type namespaces are ONLY declared on Type::Value subclasses,
1205
+ # not on Serializable models. Serializable models have element
1206
+ # namespaces, which are handled separately.
1207
+ if resolved_type.is_a?(Class) && resolved_type <= Lutaml::Model::Type::Value
1208
+ result = resolved_type.namespace_class
1209
+ end
1210
+
1211
+ @type_ns_class_cache ||= {}
1212
+ @type_ns_class_cache[register_key] = result
1213
+ end
1214
+
1215
+ # @api public
1216
+ # Get namespace URI from type
1217
+ #
1218
+ # @param register [Symbol, nil] register ID for type resolution
1219
+ # @return [String, nil] namespace URI
1220
+ def type_namespace_uri(register = nil)
1221
+ register_key = register || :default
1222
+ return @type_ns_uri_cache[register_key] if defined?(@type_ns_uri_cache) && @type_ns_uri_cache&.key?(register_key)
1223
+
1224
+ result = type_namespace_class(register_key)&.uri
1225
+ @type_ns_uri_cache ||= {}
1226
+ @type_ns_uri_cache[register_key] = result
1227
+ end
1228
+
1229
+ # @api public
1230
+ # Get namespace prefix from type
1231
+ #
1232
+ # @param register [Symbol, nil] register ID for type resolution
1233
+ # @return [String, nil] namespace prefix
1234
+ def type_namespace_prefix(register = nil)
1235
+ type_namespace_class(register)&.prefix_default
1236
+ end
1237
+
1238
+ # Copy internal state from another Attribute instance.
1239
+ # Used by `dup` to transfer processed state without calling private writers.
1240
+ def copy_internal_state_from(source)
1241
+ @raw = source.raw?
1242
+ @validations = source.validations
1243
+ end
1244
+
1245
+ # Clear type resolution caches for this attribute.
1246
+ # Called by GlobalContext.clear_caches to ensure stale entries
1247
+ # from GC'd TypeContext objects don't persist.
1248
+ def clear_type_cache
1249
+ @type_cache&.clear
1250
+ @cached_type_default = nil
1251
+ @default_type_context = nil
1252
+ @type_cache_by_register&.clear
1253
+ @type_cache_generation = nil
1254
+ end
1255
+
1256
+ # Public validation contract: mappings check their targets at
1257
+ # finalize (lutaml-model#296), the cast path checks per value.
1258
+ def validate_attr_type!(resolved_type)
1259
+ return true if resolved_type <= Serializable || resolved_type <= Type::Value
1260
+ return true if resolved_type.include?(Serialize)
1261
+
1262
+ raise Lutaml::Model::InvalidAttributeTypeError.new(name,
1263
+ resolved_type.name)
1264
+ end
1265
+
1266
+ private
1267
+
1268
+ attr_writer :raw, :validations
1269
+
1270
+ def cast_union(value, format, register)
1271
+ match = Lutaml::Model::Type::Union.conforming_member(
1272
+ value, union_member_types, format: format, register: register
1273
+ )
1274
+ match&.last
1275
+ end
1276
+
1277
+ # validated_range_object is provided by CollectionHandler module
1278
+
1279
+ def validate_name!(name, reserved_methods:)
1280
+ # No errors - all names are allowed
1281
+ # Only warn for methods where accidental override is problematic
1282
+ return unless reserved_methods.include?(name.to_sym)
1283
+ return unless self.class.warn_on_override_names.include?(name.to_sym)
1284
+
1285
+ warn_name_conflict(name)
1286
+ end
1287
+
1288
+ def warn_name_conflict(name)
1289
+ # Find the first caller location outside the lutaml-model gem's lib directory
1290
+ # This ensures we report the user's code line, not internal gem code
1291
+ gem_lib_dir = File.expand_path("../..", __dir__)
1292
+ location = caller_locations.find do |cl|
1293
+ !cl.absolute_path.to_s.start_with?(gem_lib_dir)
1294
+ end
1295
+
1296
+ Logger.warn(
1297
+ "Attribute `#{name}` overrides a method. " \
1298
+ "Ensure you call `super` if needed, or consider renaming.",
1299
+ location || caller_locations(1..1).first,
1300
+ )
1301
+ end
1302
+
1303
+ def resolve_polymorphic_class(type, value, options)
1304
+ return type unless polymorphic_map_defined?(options, value)
1305
+
1306
+ val = value[options[:polymorphic][:attribute]]
1307
+ klass_name = options[:polymorphic][:class_map][val]
1308
+ Object.const_get(klass_name)
1309
+ end
1310
+
1311
+ def polymorphic_map_defined?(polymorphic_options, value)
1312
+ !value.nil? &&
1313
+ polymorphic_options[:polymorphic] &&
1314
+ !polymorphic_options[:polymorphic].empty? &&
1315
+ value[polymorphic_options[:polymorphic][:attribute]]
1316
+ end
1317
+
1318
+ def castable?(value, format)
1319
+ value.is_a?(::Hash) ||
1320
+ ((castable_type = FormatRegistry.castable_type_for(format)) && value.is_a?(castable_type))
1321
+ end
1322
+
1323
+ def can_serialize?(klass, value, format, options)
1324
+ return false unless klass <= Serialize
1325
+
1326
+ castable?(value, format) || options[:converted]
1327
+ end
1328
+
1329
+ # custom_collection? is provided by CollectionHandler module
1330
+
1331
+ def needs_conversion?(klass, value)
1332
+ !value.nil? && !value.is_a?(klass) && Utils.initialized?(value)
1333
+ end
1334
+
1335
+ def already_serialized?(klass, value)
1336
+ klass <= Serialize && value.is_a?(klass.model)
1337
+ end
1338
+
1339
+ def serialize_array(value, format, register, options)
1340
+ value.map { |v| serialize(v, format, register, options) }
1341
+ end
1342
+
1343
+ def serialize_model(value, format, register, options)
1344
+ # Use the value's own lutaml_register if available (proper OOP - model carries its context)
1345
+ # This ensures child models serialize using their native context, not the parent's
1346
+ value_register = if value.is_a?(Lutaml::Model::Serializable) && value.lutaml_register
1347
+ value.lutaml_register
1348
+ else
1349
+ register
1350
+ end
1351
+
1352
+ as_options = Serialize::DeserializationContext.propagate(options).merge(register: value_register)
1353
+
1354
+ # Respect mapping layer policy: render_empty from MappingRule
1355
+ # Allow empty Serializable models when render_empty: true
1356
+ render_empty = options[:render_empty]
1357
+ if render_empty && value.is_a?(Lutaml::Model::Serializable)
1358
+ # Mapping layer says render this empty model - bypass present check
1359
+ else
1360
+ return unless Utils.present?(value)
1361
+ end
1362
+
1363
+ resolved_type = as_options.delete(:resolved_type) || type(register)
1364
+ if value.is_a?(resolved_type)
1365
+ return value.class.as(format, value,
1366
+ as_options)
1367
+ end
1368
+
1369
+ resolved_type.as(format, value, as_options)
1370
+ end
1371
+
1372
+ def serialize_value(value, format, resolved_type)
1373
+ # The Value wrapper is a pass-through on the to_ side (its
1374
+ # to_<format> returns the wrapped raw value unless a custom
1375
+ # format serializer is registered), so the common path returns
1376
+ # the raw value and lets the caller stringify — one object
1377
+ # instead of three per serialized scalar. Reference and
1378
+ # custom-serializer rows keep the wrapped path.
1379
+ if resolved_type <= Type::Reference ||
1380
+ (registered_to = Type::Value.format_type_serializer_for(format, resolved_type)&.dig(:to))
1381
+ # String→String under the default :xml serializer is the
1382
+ # identity — the wrapper mint per string value on the XML
1383
+ # serialize path is pure waste. A consumer override of the
1384
+ # serializer disables the fast path via the proc comparison.
1385
+ if resolved_type == Type::String && value.is_a?(::String) &&
1386
+ registered_to == Lutaml::Xml::Type::Serializers::STRING_XML_TO
1387
+ return value
1388
+ end
1389
+
1390
+ value = wrap_in_type_if_needed(value, resolved_type)
1391
+ return value.public_send(TO_FORMAT_METHODS[format] || :"to_#{format}")
1392
+ end
1393
+
1394
+ value
1395
+ end
1396
+
1397
+ def wrap_in_type_if_needed(value, resolved_type)
1398
+ return value if value.is_a?(Type::Value)
1399
+
1400
+ if resolved_type == Type::Reference
1401
+ create_reference_instance(resolved_type, value)
1402
+ else
1403
+ resolved_type.new(value)
1404
+ end
1405
+ end
1406
+
1407
+ def create_reference_instance(resolved_type, key = nil)
1408
+ resolved_type.new(@options[:ref_model_class],
1409
+ @options[:ref_key_attribute], key)
1410
+ end
1411
+
1412
+ def validate_presence!(type)
1413
+ return if type
1414
+
1415
+ raise ArgumentError, "type must be set for an attribute"
1416
+ end
1417
+
1418
+ def validate_required!(value)
1419
+ return if required_value_set?(value)
1420
+
1421
+ raise Lutaml::Model::RequiredAttributeMissingError.new(name)
1422
+ end
1423
+
1424
+ def set_default_for_collection
1425
+ validate_collection_range
1426
+ attr = self
1427
+ if initialize_empty? && !@options[:default]
1428
+ @options[:default] = -> { attr.build_collection }
1429
+ @implicit_collection_default = true
1430
+ end
1431
+ end
1432
+
1433
+ def validate_options!(options)
1434
+ if (invalid_opts = options.keys - ALLOWED_OPTIONS).any?
1435
+ raise Lutaml::Model::InvalidAttributeOptionsError.new(name,
1436
+ invalid_opts)
1437
+ end
1438
+
1439
+ # Deprecation warning for :xsd_type attribute option
1440
+ if options.key?(:xsd_type)
1441
+ warn "[DEPRECATION] The :xsd_type attribute option is deprecated and will be removed in v1.0.0. " \
1442
+ "Create a custom Type::Value class with xsd_type at class level instead. " \
1443
+ "See: docs/migration-guides/xsd-type-migration.adoc " \
1444
+ "Called from #{caller(1..1).first}"
1445
+ end
1446
+
1447
+ # pattern applies to string values: a plain :string attribute, or a
1448
+ # union that includes a :string member (the pattern binds that branch).
1449
+ # Guarded by the pattern key so non-pattern attributes never resolve
1450
+ # their type here (custom types may be absent from the default register).
1451
+ if options.key?(:pattern)
1452
+ union_with_string =
1453
+ type == Lutaml::Model::Type::Union &&
1454
+ Array(options[:union_member_types]).intersect?(MODEL_STRINGS)
1455
+ unless MODEL_STRINGS.include?(type) || union_with_string
1456
+ raise StandardError,
1457
+ "Invalid option `pattern` given for `#{name}`, " \
1458
+ "`pattern` is only allowed for :string type or a union " \
1459
+ "including a :string member"
1460
+ end
1461
+ end
1462
+
1463
+ if initialize_empty? && !collection?
1464
+ raise StandardError,
1465
+ "Invalid option `initialize_empty` given without `collection: true` option"
1466
+ end
1467
+
1468
+ # Length facets are XSD nonNegativeInteger; reject a misconfigured
1469
+ # type here so a String/Float/nil fails fast instead of raising an
1470
+ # opaque TypeError later at `value.length >= min`.
1471
+ %i[min_length max_length].each do |key|
1472
+ next unless options.key?(key)
1473
+
1474
+ value = options[key]
1475
+ next if value.is_a?(::Integer) && !value.negative?
1476
+
1477
+ raise ArgumentError,
1478
+ "Invalid options for `#{name}`: " \
1479
+ "`#{key}` must be a non-negative Integer, got #{value.inspect}"
1480
+ end
1481
+
1482
+ # `signed` is true|false per issue #191; a non-boolean (e.g. "false")
1483
+ # would silently read as signed, so reject it up front.
1484
+ if options.key?(:signed) && ![true, false].include?(options[:signed])
1485
+ raise ArgumentError,
1486
+ "Invalid options for `#{name}`: " \
1487
+ "`signed` must be true or false, got #{options[:signed].inspect}"
1488
+ end
1489
+ true
1490
+ end
1491
+
1492
+ def validate_type!(type)
1493
+ return true if [Symbol,
1494
+ String].include?(type.class) || type.is_a?(Class)
1495
+
1496
+ raise ArgumentError,
1497
+ "Invalid type: #{type}, must be a Symbol, String or a Class"
1498
+ end
1499
+
1500
+ def valid_polymorphic_type?(value, resolved_type)
1501
+ return value.is_a?(type) unless has_polymorphic_list?
1502
+
1503
+ options[:polymorphic].include?(value.class) && value.is_a?(resolved_type)
1504
+ end
1505
+
1506
+ def has_polymorphic_list?
1507
+ options[:polymorphic]&.is_a?(Array)
1508
+ end
1509
+ end
1510
+ end
1511
+ end