lutaml-lml 0.3.5 → 0.3.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (114) hide show
  1. checksums.yaml +4 -4
  2. data/lib/lutaml-lml.rb +5 -0
  3. data/lib/lutaml_lml/version.rb +6 -0
  4. metadata +12 -164
  5. data/exe/lutaml-lml +0 -6
  6. data/exe/lutaml-lml-lsp +0 -11
  7. data/lib/lutaml/lml/association_label_resolver.rb +0 -52
  8. data/lib/lutaml/lml/cli.rb +0 -489
  9. data/lib/lutaml/lml/data_processor/attribute_processing.rb +0 -133
  10. data/lib/lutaml/lml/data_processor/collection_processing.rb +0 -37
  11. data/lib/lutaml/lml/data_processor/instance_processing.rb +0 -77
  12. data/lib/lutaml/lml/data_processor/value_declaration_processing.rb +0 -70
  13. data/lib/lutaml/lml/data_processor/value_processing.rb +0 -103
  14. data/lib/lutaml/lml/data_processor/view_processing.rb +0 -26
  15. data/lib/lutaml/lml/data_processor.rb +0 -59
  16. data/lib/lutaml/lml/diagnostic.rb +0 -149
  17. data/lib/lutaml/lml/document_builder.rb +0 -481
  18. data/lib/lutaml/lml/entity_types.rb +0 -30
  19. data/lib/lutaml/lml/executor/adapter_helpers.rb +0 -45
  20. data/lib/lutaml/lml/executor/condition_evaluator.rb +0 -169
  21. data/lib/lutaml/lml/executor/csv_adapter.rb +0 -88
  22. data/lib/lutaml/lml/executor/format_adapter.rb +0 -54
  23. data/lib/lutaml/lml/executor/xml_adapter.rb +0 -102
  24. data/lib/lutaml/lml/executor.rb +0 -96
  25. data/lib/lutaml/lml/format/adapter/document.rb +0 -11
  26. data/lib/lutaml/lml/format/adapter/mapping.rb +0 -31
  27. data/lib/lutaml/lml/format/adapter/standard_adapter.rb +0 -162
  28. data/lib/lutaml/lml/format/adapter/transform.rb +0 -11
  29. data/lib/lutaml/lml/format.rb +0 -29
  30. data/lib/lutaml/lml/formatter/base.rb +0 -79
  31. data/lib/lutaml/lml/formatter/canonical.rb +0 -736
  32. data/lib/lutaml/lml/formatter/elk.rb +0 -45
  33. data/lib/lutaml/lml/formatter/graphviz/document_formatter.rb +0 -89
  34. data/lib/lutaml/lml/formatter/graphviz/html_builder.rb +0 -72
  35. data/lib/lutaml/lml/formatter/graphviz/node_formatter.rb +0 -89
  36. data/lib/lutaml/lml/formatter/graphviz/relationship_formatter.rb +0 -130
  37. data/lib/lutaml/lml/formatter/graphviz.rb +0 -90
  38. data/lib/lutaml/lml/formatter/svg_pdf/path_parser.rb +0 -134
  39. data/lib/lutaml/lml/formatter/svg_pdf.rb +0 -285
  40. data/lib/lutaml/lml/formatter.rb +0 -12
  41. data/lib/lutaml/lml/grammar/lml.artifact.json +0 -14993
  42. data/lib/lutaml/lml/grammar/lml.parg +0 -389
  43. data/lib/lutaml/lml/grammar.rb +0 -60
  44. data/lib/lutaml/lml/has_attributes.rb +0 -14
  45. data/lib/lutaml/lml/import_resolver.rb +0 -96
  46. data/lib/lutaml/lml/layout/elk_engine.rb +0 -15
  47. data/lib/lutaml/lml/layout/elk_graph_builder.rb +0 -129
  48. data/lib/lutaml/lml/layout/elk_svg_markers.rb +0 -45
  49. data/lib/lutaml/lml/layout/elk_svg_renderer.rb +0 -119
  50. data/lib/lutaml/lml/layout/engine.rb +0 -17
  51. data/lib/lutaml/lml/layout/graph_viz_engine.rb +0 -19
  52. data/lib/lutaml/lml/layout.rb +0 -12
  53. data/lib/lutaml/lml/literal_value.rb +0 -32
  54. data/lib/lutaml/lml/lsp/conversions.rb +0 -78
  55. data/lib/lutaml/lml/lsp/keywords.rb +0 -43
  56. data/lib/lutaml/lml/lsp/server.rb +0 -378
  57. data/lib/lutaml/lml/lsp/store.rb +0 -68
  58. data/lib/lutaml/lml/lsp/transport.rb +0 -53
  59. data/lib/lutaml/lml/lsp.rb +0 -16
  60. data/lib/lutaml/lml/model_compiler/enums.rb +0 -172
  61. data/lib/lutaml/lml/model_compiler/hydration.rb +0 -123
  62. data/lib/lutaml/lml/model_compiler/serialization_mappings.rb +0 -188
  63. data/lib/lutaml/lml/model_compiler/string_formats.rb +0 -42
  64. data/lib/lutaml/lml/model_compiler/validation.rb +0 -65
  65. data/lib/lutaml/lml/model_compiler.rb +0 -323
  66. data/lib/lutaml/lml/models/action.rb +0 -10
  67. data/lib/lutaml/lml/models/association.rb +0 -29
  68. data/lib/lutaml/lml/models/cardinality.rb +0 -10
  69. data/lib/lutaml/lml/models/collection.rb +0 -11
  70. data/lib/lutaml/lml/models/constraint.rb +0 -23
  71. data/lib/lutaml/lml/models/data_type.rb +0 -41
  72. data/lib/lutaml/lml/models/derived_field.rb +0 -14
  73. data/lib/lutaml/lml/models/diagram.rb +0 -20
  74. data/lib/lutaml/lml/models/document.rb +0 -84
  75. data/lib/lutaml/lml/models/enum.rb +0 -38
  76. data/lib/lutaml/lml/models/fidelity.rb +0 -10
  77. data/lib/lutaml/lml/models/group.rb +0 -11
  78. data/lib/lutaml/lml/models/instance.rb +0 -26
  79. data/lib/lutaml/lml/models/instance_collection.rb +0 -16
  80. data/lib/lutaml/lml/models/instances_export.rb +0 -10
  81. data/lib/lutaml/lml/models/instances_import.rb +0 -11
  82. data/lib/lutaml/lml/models/mapping.rb +0 -15
  83. data/lib/lutaml/lml/models/mapping_rule.rb +0 -16
  84. data/lib/lutaml/lml/models/member_field.rb +0 -14
  85. data/lib/lutaml/lml/models/namespace.rb +0 -16
  86. data/lib/lutaml/lml/models/operation.rb +0 -26
  87. data/lib/lutaml/lml/models/operation_parameter.rb +0 -12
  88. data/lib/lutaml/lml/models/package.rb +0 -26
  89. data/lib/lutaml/lml/models/primitive_type.rb +0 -33
  90. data/lib/lutaml/lml/models/reference.rb +0 -23
  91. data/lib/lutaml/lml/models/serialization_mapping.rb +0 -19
  92. data/lib/lutaml/lml/models/string_format.rb +0 -16
  93. data/lib/lutaml/lml/models/top_element_attribute.rb +0 -116
  94. data/lib/lutaml/lml/models/uml_class.rb +0 -85
  95. data/lib/lutaml/lml/models/value.rb +0 -15
  96. data/lib/lutaml/lml/models/view_filter.rb +0 -11
  97. data/lib/lutaml/lml/models/view_import.rb +0 -11
  98. data/lib/lutaml/lml/parser.rb +0 -19
  99. data/lib/lutaml/lml/pipeline.rb +0 -73
  100. data/lib/lutaml/lml/positioned.rb +0 -13
  101. data/lib/lutaml/lml/preprocessor.rb +0 -130
  102. data/lib/lutaml/lml/quoting.rb +0 -60
  103. data/lib/lutaml/lml/source.rb +0 -49
  104. data/lib/lutaml/lml/source_position.rb +0 -20
  105. data/lib/lutaml/lml/symbol_index.rb +0 -200
  106. data/lib/lutaml/lml/transform.rb +0 -119
  107. data/lib/lutaml/lml/types/text_type.rb +0 -28
  108. data/lib/lutaml/lml/types.rb +0 -10
  109. data/lib/lutaml/lml/validator.rb +0 -458
  110. data/lib/lutaml/lml/version.rb +0 -7
  111. data/lib/lutaml/lml/view_resolution.rb +0 -32
  112. data/lib/lutaml/lml/view_resolver.rb +0 -48
  113. data/lib/lutaml/lml/yaml_parser.rb +0 -17
  114. data/lib/lutaml/lml.rb +0 -130
@@ -1,481 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Lutaml
4
- module Lml
5
- # Builds domain model objects from processed parse hashes, applying
6
- # source positions as non-serialized metadata.
7
- class DocumentBuilder
8
- # Default registry: builder keys → LML model classes.
9
- # Callers needing a different mapping can pass their own registry
10
- # to `new`; this constant documents the default composition.
11
- DEFAULT_REGISTRY = {
12
- document: ::Lutaml::Lml::Document,
13
- package: ::Lutaml::Lml::Package,
14
- class: ::Lutaml::Lml::UmlClass,
15
- enum: ::Lutaml::Lml::Enum,
16
- data_type: ::Lutaml::Lml::DataType,
17
- diagram: ::Lutaml::Lml::Diagram,
18
- attribute: ::Lutaml::Lml::TopElementAttribute,
19
- cardinality: ::Lutaml::Lml::Cardinality,
20
- association: ::Lutaml::Lml::Association,
21
- operation: ::Lutaml::Lml::Operation,
22
- constraint: ::Lutaml::Lml::Constraint,
23
- value: ::Lutaml::Lml::Value,
24
- instance: ::Lutaml::Lml::Instance,
25
- instance_collection: ::Lutaml::Lml::InstanceCollection,
26
- view_import: ::Lutaml::Lml::ViewImport,
27
- view_filter: ::Lutaml::Lml::ViewFilter,
28
- mapping: ::Lutaml::Lml::Mapping,
29
- string_format: ::Lutaml::Lml::StringFormat,
30
- derived_field: ::Lutaml::Lml::DerivedField,
31
- member_field: ::Lutaml::Lml::MemberField,
32
- namespace: ::Lutaml::Lml::Namespace,
33
- serialization_mapping: ::Lutaml::Lml::SerializationMapping,
34
- }.freeze
35
-
36
- attr_reader :registry
37
-
38
- def initialize(registry = DEFAULT_REGISTRY)
39
- @registry = registry
40
- end
41
-
42
- FACTORY_KEYS = %i[
43
- document package class enum data_type diagram view_import view_filter
44
- attribute association operation constraint value cardinality mapping
45
- string_format derived_field namespace serialization_mapping
46
- instance instance_collection
47
- ].freeze
48
-
49
- MEMBER_KEY_MAP = {
50
- packages: :package,
51
- classes: :class,
52
- enums: :enum,
53
- data_types: :data_type,
54
- diagrams: :diagram,
55
- view_imports: :view_import,
56
- attributes: :attribute,
57
- associations: :association,
58
- operations: :operation,
59
- constraints: :constraint,
60
- values: :value,
61
- mappings: :mapping,
62
- member_fields: :member_field,
63
- namespaces: :namespace,
64
- serialization_mappings: :serialization_mapping,
65
- instances: :instance,
66
- }.freeze
67
-
68
- FACTORY_KEYS.each do |key|
69
- define_method(:"build_#{key}") { |hash| build(key, hash) }
70
- end
71
-
72
- def build(key, hash)
73
- @registry.fetch(key).new.tap { |model| set_model(model, hash) }
74
- end
75
-
76
- private
77
-
78
- def set_model(model, hash)
79
- hash = build_members(model, hash)
80
- apply_collection_members(model, hash)
81
- set_model_attributes(model, hash)
82
- expand_class_specializer(model, hash)
83
- end
84
-
85
- # The prefix specializer (`abstract class Foo`) expands to the
86
- # canonical `abstract true` declaration (RS 3001 par. Declaration
87
- # modifiers); the class-level modifier capture is not a block member.
88
- def expand_class_specializer(model, hash)
89
- return unless hash[:modifier].to_s == 'abstract' && model.class.attributes.key?(:is_abstract)
90
-
91
- model.is_abstract = true
92
- end
93
-
94
- def set_model_attributes(model, hash)
95
- hash.each do |key, value|
96
- if key == :position
97
- attach_position(model, value)
98
- next
99
- end
100
-
101
- apply_attribute(model, key, value)
102
- end
103
- end
104
-
105
- def attach_position(model, value)
106
- return unless model.is_a?(Positioned) && value.is_a?(Hash)
107
-
108
- model.source_position = SourcePosition.new(**value)
109
- end
110
-
111
- def build_members(model, hash)
112
- members = hash.delete(:members)
113
- members.to_a.each do |member_hash|
114
- record_model_version(model, member_hash)
115
- add_members(model, member_hash)
116
- set_model_attributes(model, member_hash)
117
- end
118
- hash
119
- end
120
-
121
- # A `models <Name> version "x.y.z"` header travels with the block's
122
- # member hash; the block itself flattens into the document, so the
123
- # version is recorded on the document before the name is dropped.
124
- def record_model_version(model, hash)
125
- return unless model.class.attributes.key?(:model_versions)
126
- return unless hash.key?(:version)
127
-
128
- name = hash[:name].to_s
129
- model.model_versions[name] = unquote(hash.delete(:version)).to_s
130
- end
131
-
132
- def apply_attribute(model, key, value)
133
- return unless model.class.attributes.key?(key.to_sym)
134
-
135
- if model.class.attributes[key.to_sym].options[:collection]
136
- append_collection(model, key, value)
137
- else
138
- model.public_send("#{key}=", value)
139
- end
140
- end
141
-
142
- def append_collection(model, key, value)
143
- values = model.public_send(key).to_a
144
- value.is_a?(Array) ? values.concat(value) : values << value
145
- model.public_send("#{key}=", values)
146
- end
147
-
148
- def add_members(model, hash)
149
- expand_declared_members(model, hash)
150
- normalize_namespace_declaration(hash)
151
- normalize_serialization_mapping(hash)
152
- expand_instances_collection_name(hash)
153
- expand_nested_members(model, hash)
154
- apply_collection_members(model, hash)
155
-
156
- remap_filter_keys(hash, model)
157
- end
158
-
159
- # Builds collection-shaped keys through the registry rather than
160
- # letting lutaml-model cast raw hashes, so nested entities keep
161
- # their non-serialized source metadata (positions).
162
- def apply_collection_members(model, hash)
163
- model.instances = build(:instance_collection, hash.delete(:instances)) if model.is_a?(Document) && hash.key?(:instances)
164
-
165
- MEMBER_KEY_MAP.each do |plural_key, singular_key|
166
- data = hash.delete(plural_key)
167
- next if data.nil?
168
-
169
- entries = data.is_a?(Array) ? data : [data]
170
- entries.each do |entry|
171
- ensure_collection(model, plural_key) << build(singular_key, entry)
172
- end
173
- end
174
- end
175
-
176
- # RS 3001 §Enums: an enum-level `values { v1, v2 }` shorthand
177
- # expands into plain members.
178
- def expand_value_set_declaration(model, hash)
179
- decl = hash.delete(:value_set_decl) or return
180
- Array(decl[:items]).each do |item|
181
- name = unquote(item[:item])
182
- model.attributes << TopElementAttribute.new(name: name)
183
- end
184
- end
185
-
186
- # RS 3001 §Value: the canonical `value` construct normalizes into
187
- # the same member shape the bare-identifier shortcut produces.
188
- def expand_value_declaration(model, hash)
189
- decl = hash.delete(:value_decl) or return
190
- inner = decl.fetch(:attributes)
191
-
192
- # Route the value block's members onto the entry: descriptions
193
- # and payload pairs ride the nested attributes, instance bodies
194
- # become the entry's instances (RS 3001 §Enums values carrying
195
- # instances).
196
- entry = { name: inner[:name] }
197
- entry[:position] = inner[:position] if inner[:position]
198
- entry[:attributes] = inner[:attributes] if inner[:attributes]
199
- if inner[:properties]
200
- entry[:properties] = Array(inner[:properties]).flat_map do |pair|
201
- pair.is_a?(Hash) ? [pair] : Array(pair)
202
- end
203
- end
204
- entry[:instances] = inner[:instances] if inner[:instances]
205
- append_collection(model, :attributes, build(:attribute, entry))
206
- end
207
-
208
- # Namespace declaration bodies arrive as keyword-line members
209
- # ({uri: …}, {prefix: …}); flatten them onto the namespace hash.
210
- def normalize_namespace_declaration(hash)
211
- ns = hash[:namespaces] or return
212
- Array(ns.delete(:members)).each do |pair|
213
- pair.each { |key, value| ns[key] = unquote(value) }
214
- end
215
- end
216
-
217
- # Serialization mapping rules arrive keyed by their line construct
218
- # ({map_element: {wire:, field:}}); normalize into plain MappingRule
219
- # hashes so the model cast lands typed rules.
220
- def normalize_serialization_mapping(hash)
221
- mapping = hash[:serialization_mappings] or return
222
- rules = Array(mapping[:rules])
223
- return if rules.any? && rules.all? { |e| e.is_a?(Hash) && e.key?(:kind) }
224
-
225
- rules = rules.filter_map do |entry|
226
- next nil unless entry.is_a?(Hash)
227
-
228
- next { kind: 'map', wire: unquote(entry[:wire]), field: unquote(entry[:to]) } if entry[:wire] && entry[:to]
229
-
230
- first_key = entry.keys.first
231
- kind = first_key.to_s
232
- body = entry[first_key] || {}
233
- unless body.is_a?(Hash)
234
- kind_n = normalize_mapping_kind(kind)
235
- next nil if body.to_s.empty?
236
-
237
- term = unquote(body)
238
- next { kind: kind_n, wire: term, field: term } if %w[element attribute map].include?(kind_n)
239
-
240
- if kind_n == 'namespace'
241
- mapping[:namespace_ref] = term
242
- next nil
243
- end
244
-
245
- next { kind: kind_n, field: term }
246
- end
247
- if kind == 'element_name'
248
- mapping[:element_name] = unquote(body[:element_name])
249
- next nil
250
- end
251
- if kind == 'map_namespace'
252
- mapping[:namespace_ref] = unquote(body[:namespace_ref])
253
- next nil
254
- end
255
- normalized = { kind: normalize_mapping_kind(kind) }
256
- wire = body[:wire] || body[:element_wire]
257
- normalized[:wire] = unquote(wire) if wire
258
- field = body[:field] || body[:to_field] || body[:element_field] ||
259
- body[:attribute_field] || body[:to]
260
- normalized[:field] = unquote(field) if field
261
- normalized[:mode] = body[:mode] if body[:mode]
262
- normalized[:namespace_ref] = unquote(body[:namespace_ref]) if body[:namespace_ref]
263
- normalized
264
- end
265
- mapping[:rules] = rules
266
- end
267
-
268
- def normalize_mapping_kind(kind)
269
- {
270
- 'map_element' => 'element', 'map_attribute' => 'attribute',
271
- 'map_content' => 'content', 'map_namespace' => 'namespace',
272
- 'map_key' => 'key', 'map_value' => 'value', 'map' => 'map',
273
- 'legacy_map' => 'map'
274
- }.fetch(kind, kind)
275
- end
276
-
277
- # A named instances collection (`instances "Glazes" { ... }`) arrives
278
- # with its name as a sibling of the collection body; move it inside
279
- # so the InstanceCollection carries it.
280
- def expand_instances_collection_name(hash)
281
- return unless hash.key?(:instances) && hash.key?(:name)
282
-
283
- name = unquote(hash.delete(:name))
284
- body = hash[:instances].is_a?(Hash) ? hash[:instances] : {}
285
- body[:name] = name unless body.key?(:name)
286
- end
287
-
288
- # The document root is a repetition of top-level constructs (RS 3001:
289
- # documents interleave declarations), so models/packages blocks nest
290
- # their members one level down; recurse into them.
291
- def expand_nested_members(model, hash)
292
- return unless hash.key?(:members)
293
-
294
- members = hash.delete(:members)
295
- members.to_a.each do |nested|
296
- add_members(model, nested)
297
- set_model_attributes(model, nested)
298
- end
299
- end
300
-
301
- # Declaration-level member hooks: single-line definitions, canonical
302
- # `value` members, mapping sections, class declarations, enum
303
- # member_fields and from_table all arrive as bare member hashes.
304
- def expand_declared_members(model, hash)
305
- expand_abstract_declaration(model, hash)
306
- expand_definition_text(model, hash)
307
- expand_value_declaration(model, hash)
308
- expand_value_set_declaration(model, hash)
309
- expand_mapping_section(model, hash)
310
- expand_class_declarations(model, hash)
311
- expand_enum_member_fields(model, hash)
312
- expand_from_table(model, hash)
313
- expand_operation_members(model, hash)
314
- end
315
-
316
- # Operation members arrive with grammar capture names
317
- # (`visibility_modifier`, `param_default`) and per-iteration
318
- # stereotype hashes; normalize to the model's field names.
319
- def expand_operation_members(model, hash)
320
- ops = hash.delete(:operations)
321
- return unless ops && model.class.attributes.key?(:operations)
322
-
323
- Array(ops.is_a?(Hash) ? [ops] : ops).each do |op|
324
- model.operations << build(:operation, normalize_operation_hash(op))
325
- end
326
- end
327
-
328
- def normalize_operation_hash(operation)
329
- operation = operation.dup
330
- if (vis = operation.delete(:visibility_modifier))
331
- operation[:visibility] = Transform::VISIBILITY_MAP.fetch(vis.to_s, 'public')
332
- end
333
- stereo = operation[:stereotype]
334
- if stereo
335
- items = stereo.is_a?(Array) ? stereo : [stereo]
336
- operation[:stereotype] = items.map { |x| x.is_a?(Hash) ? x[:stereotype].to_s : x.to_s }
337
- end
338
- params = operation[:owned_parameter]
339
- if params
340
- list = params.is_a?(Array) ? params : [params]
341
- operation[:owned_parameter] = list.map { |param| normalize_operation_param(param) }
342
- end
343
- operation
344
- end
345
-
346
- def normalize_operation_param(param)
347
- param = param.dup
348
- if (default = param.delete(:param_default))
349
- param[:default] = default.is_a?(Hash) ? default[:string].to_s : default.to_s
350
- end
351
- param
352
- end
353
-
354
- # RS 3001 §Definition single-line form (`definition "text"`) arrives
355
- # as a quoted-string capture; unwrap it for the entity's definition.
356
- # RS 3001 declaration modifiers: `abstract true` maps onto the
357
- # is_abstract field (the visibility declaration flows through the
358
- # generic attribute path).
359
- def expand_abstract_declaration(model, hash)
360
- value = hash.delete(:abstract)
361
- model.is_abstract = true if value.to_s == 'true' && model.class.attributes.key?(:is_abstract)
362
- end
363
-
364
- def expand_definition_text(model, hash)
365
- return unless hash.key?(:definition) && model.class.attributes.key?(:definition)
366
-
367
- model.definition = unquote(hash.delete(:definition))
368
- end
369
-
370
- # A mapping section arrives as a bare member hash
371
- # { format:, maps: [{ wire:, to: }] }; expand to one Mapping entry
372
- # per map line, each carrying the format, and strip the section keys
373
- def expand_mapping_section(model, hash)
374
- section = mapping_section_from(hash)
375
- return unless section
376
-
377
- section[:maps].to_a.each do |line|
378
- model.wire_mappings << build(:mapping,
379
- format: section[:format],
380
- wire: unquote(line[:wire]),
381
- to: unquote(line[:to]))
382
- end
383
- end
384
-
385
- def mapping_section_from(hash)
386
- return { format: unquote(hash[:format]), maps: hash.delete(:maps) } if hash.key?(:maps)
387
-
388
- hash.delete(:mappings)
389
- end
390
-
391
- # quoted_string captures nest their value under :string
392
- def unquote(value)
393
- value.is_a?(Hash) && value.key?(:string) ? value[:string] : value
394
- end
395
-
396
- # L5/L7 declaration members: string_format sections (class- or
397
- # models-level), derive lines, and enum member_fields blocks
398
- def expand_class_declarations(model, hash)
399
- if (section = hash.delete(:string_format))
400
- model.string_formats << build_string_format(section)
401
- end
402
- if (section = hash.delete(:default_string_formats))
403
- model.default_string_formats << build_string_format(section)
404
- end
405
- expand_class_namespace(model, hash)
406
- return unless (derived = hash.delete(:derived_field))
407
-
408
- model.derived_fields << build(:derived_field,
409
- name: derived[:name],
410
- type: unquote(derived[:type]))
411
- end
412
-
413
- # Issue #49: an in-class `namespace "uri" [prefix "p"]` line
414
- def expand_class_namespace(model, hash)
415
- decl = hash.delete(:class_namespace) or return
416
-
417
- model.xml_namespace = build(:namespace,
418
- uri: unquote(decl[:uri]),
419
- prefix: unquote(decl[:prefix]))
420
- end
421
-
422
- # L7a: from_table declares the enum's members as an artifact table
423
- # { from_table_name:, from_table_artifact? } — expansion happens at
424
- # compile time (deterministic materialization, no runtime data dep)
425
- def expand_from_table(model, hash)
426
- decl = hash.delete(:from_table_decl)
427
- return unless decl && model.is_a?(Enum)
428
-
429
- # the members repetition splits the declaration across iteration
430
- # hashes (name part, artifact part) — merge the parts
431
- parts = decl.is_a?(Array) ? decl : [decl]
432
- decl = parts.each_with_object({}) do |part, acc|
433
- acc.merge!(part) { |_key, _old, new_val| new_val }
434
- end
435
- model.from_table_name = unquote(decl[:from_table_name])
436
- model.from_table_artifact = unquote(decl[:artifact_table]) if decl[:artifact_table]
437
- end
438
-
439
- def expand_enum_member_fields(model, hash)
440
- decl = hash.delete(:member_fields_decl)
441
- return unless decl && model.is_a?(Enum)
442
-
443
- decl[:member_fields].to_a.each do |field|
444
- model.member_fields << build(:member_field,
445
- name: field[:name],
446
- type: unquote(field[:member_field_type]))
447
- end
448
- end
449
-
450
- def build_string_format(section)
451
- items = section[:items].to_a.to_h do |item|
452
- [item[:key].to_sym, unquote(item[:value])]
453
- end
454
- build(:string_format,
455
- format: unquote(section[:format]),
456
- artifact: items[:artifact],
457
- root: items[:root])
458
- end
459
-
460
- def ensure_collection(model, key)
461
- model.public_send(key) || begin
462
- model.public_send("#{key}=", [])
463
- model.public_send(key)
464
- end
465
- end
466
-
467
- def remap_filter_keys(hash, model)
468
- return unless model.is_a?(Document)
469
-
470
- hash[:show_filter] = build_view_filter(hash.delete(:show_list)) if hash.key?(:show_list)
471
- return unless hash.key?(:hide_list)
472
-
473
- hash[:hide_filter] = build_view_filter(hash.delete(:hide_list))
474
- end
475
-
476
- def build_view_filter(entity_names)
477
- ViewFilter.new(entity_names: Array(entity_names).map(&:to_s))
478
- end
479
- end
480
- end
481
- end
@@ -1,30 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Lutaml
4
- module Lml
5
- # Single source of truth for entity types held on a Document. Each
6
- # entity model declares self.entity_type (the Document collection
7
- # name); consumers iterate this registry instead of hardcoding the
8
- # type list in four places.
9
- module EntityTypes
10
- ALL = [UmlClass, Enum, DataType, PrimitiveType].freeze
11
-
12
- def self.all
13
- ALL
14
- end
15
-
16
- def self.by_symbol
17
- @by_symbol ||= ALL.each_with_object({}) { |klass, index| index[klass.entity_type] = klass }
18
- end
19
-
20
- def self.symbols
21
- by_symbol.keys
22
- end
23
-
24
- # Entities that can own attributes/associations (excludes enums).
25
- def self.classifiable
26
- ALL.select(&:classifiable?)
27
- end
28
- end
29
- end
30
- end
@@ -1,45 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Lutaml
4
- module Lml
5
- class Executor
6
- # Shared helpers for the I/O adapters. Both CsvAdapter and XmlAdapter
7
- # need to:
8
- #
9
- # - resolve a `map_to` reference to a compiled class
10
- # - look up attribute values by name in an import/export definition
11
- # - find the compiled class that an instance belongs to (for export)
12
- #
13
- # This module owns those three concerns so each adapter can stay
14
- # focused on its format-specific I/O.
15
- module AdapterHelpers
16
- # Returns the compiled class referenced by the `map_to` attribute,
17
- # or nil if no such attribute or no such compiled class.
18
- def resolve_target_class(attributes, compiled)
19
- attr = find_attribute(attributes, "map_to")
20
- return nil unless attr
21
-
22
- compiled[attr.value.to_s]
23
- end
24
-
25
- # Returns the string value of the named attribute, or nil.
26
- def attribute_value(attributes, name)
27
- attr = find_attribute(attributes, name)
28
- attr ? attr.value.to_s : nil
29
- end
30
-
31
- # Walks an attributes collection looking for an entry whose
32
- # `.name` matches `name`. Returns the attribute, or nil.
33
- def find_attribute(attributes, name)
34
- Array(attributes).find { |a| a.name == name }
35
- end
36
-
37
- # Returns [class_name, klass] for the first compiled class whose
38
- # instances include `first_instance`, or nil if no match.
39
- def find_class_for_instance(first_instance, compiled)
40
- compiled.find { |_name, klass| first_instance.is_a?(klass) }
41
- end
42
- end
43
- end
44
- end
45
- end