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,323 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'json'
4
-
5
- module Lutaml
6
- module Lml
7
- # Compiles LML model definitions into anonymous
8
- # Lutaml::Model::Serializable subclasses, hydrates instance data
9
- # against them, and applies declared serialization mappings. The
10
- # concern modules (Hydration, Validation, Enums,
11
- # SerializationMappings, StringFormats) share this class's state.
12
- class ModelCompiler
13
- autoload :Hydration, "lutaml/lml/model_compiler/hydration"
14
- autoload :Validation, "lutaml/lml/model_compiler/validation"
15
- autoload :Enums, "lutaml/lml/model_compiler/enums"
16
- autoload :SerializationMappings, "lutaml/lml/model_compiler/serialization_mappings"
17
- autoload :StringFormats, "lutaml/lml/model_compiler/string_formats"
18
-
19
- class ValidationError < Error; end
20
-
21
- # The default generated namespace nests under Lutaml::Lml so
22
- # compiled constants never collide with top-level constants.
23
- DEFAULT_NAMESPACE = 'Lutaml::Lml::Generated'
24
-
25
- TYPE_MAP = {
26
- 'String' => :string,
27
- 'string' => :string,
28
- 'Integer' => :integer,
29
- 'integer' => :integer,
30
- 'Boolean' => :boolean,
31
- 'boolean' => :boolean,
32
- 'Float' => :float,
33
- 'float' => :float,
34
- 'Date' => :date,
35
- 'date_time' => :date_time,
36
- 'DateTime' => :date_time,
37
- 'Time' => :time,
38
- 'Uri' => :string,
39
- }.freeze
40
-
41
- # Tokens that denote unbounded cardinality in LML attribute
42
- # declarations. Anything else must parse as an Integer.
43
- UNBOUNDED_TOKENS = %w[* n N unbounded].freeze
44
-
45
- include Hydration
46
- include Validation
47
- include Enums
48
- include SerializationMappings
49
- include StringFormats
50
-
51
- def initialize(namespace: nil, artifact_paths: {}, default_artifact: nil)
52
- @namespace = namespace
53
- @artifact_paths = artifact_paths
54
- @default_artifact = default_artifact
55
- @compiled = {}
56
- @forward_refs = {}
57
- @enum_names = Set.new
58
- @enum_classes = {}
59
- @declared_namespaces = []
60
- @serialization_mappings = []
61
- @namespace_classes = {}
62
- @class_defs = {}
63
- end
64
-
65
- def compile(input)
66
- doc = Lutaml::Lml.parse_document(input)
67
- compile_document(doc)
68
- @compiled
69
- end
70
-
71
- def hydrate(input)
72
- doc = input.is_a?(Document) ? input : Lutaml::Lml.parse_document(input)
73
- compile_document(doc) unless @compiled.any?
74
- return {} unless doc.instance
75
-
76
- hydrate_instance(doc.instance)
77
- rescue Lutaml::Lml::Error
78
- raise
79
- rescue StandardError => e
80
- raise HydrationError.new(
81
- "hydration failed: #{e.message}",
82
- diagnostic: Diagnostic.build(
83
- 'hydration/LML-H01',
84
- message: e.message,
85
- file: input.is_a?(Document) ? input.source_path : nil,
86
- ),
87
- )
88
- end
89
-
90
- def compiled_classes
91
- @compiled
92
- end
93
-
94
- # Validate an instances document against compiled models.
95
- #
96
- # Accepts the instances input as a String, IO, StringIO, or a
97
- # pre-parsed Document. If +compiled:+ is supplied, that registry is
98
- # used; otherwise models are compiled from the same input (which
99
- # must therefore contain a models section).
100
- #
101
- # Returns an array of validation error strings (empty if all pass).
102
- def validate(input, compiled: nil)
103
- doc = input.is_a?(Document) ? input : Lutaml::Lml.parse_document(input)
104
- if compiled
105
- @compiled = compiled
106
- else
107
- compile_document(doc)
108
- end
109
-
110
- errors = []
111
- validate_instance(doc.instance, errors) if doc.instance
112
- errors
113
- end
114
-
115
- private
116
-
117
- def compile_document(doc)
118
- @declared_namespaces = Array(doc.namespaces)
119
- @serialization_mappings = Array(doc.serialization_mappings)
120
- doc.classes.each { |c| compile_class(c) }
121
- hoist_class_serialization_mappings(doc)
122
- doc.enums.each { |e| compile_enum(e) }
123
- doc.data_types.each { |dt| compile_data_type(dt) }
124
- resolve_forward_references
125
- apply_xml_mappings
126
- apply_key_value_mappings
127
- register_string_formats(doc)
128
- end
129
-
130
- def resolve_forward_references
131
- @forward_refs.each do |class_name, deferred_attrs|
132
- klass = @compiled[class_name]
133
- next unless klass
134
-
135
- deferred_attrs.each do |attr_name, raw_type, _type, options|
136
- resolved = resolve_type(raw_type)
137
- klass.attribute attr_name, resolved, **options
138
- end
139
- end
140
- end
141
-
142
- def compile_class(klass_def)
143
- name = klass_def.name.to_s
144
- @class_defs[name] = klass_def
145
- compiled_klass = build_compiled_class(klass_def)
146
- apply_declared_mappings(compiled_klass, klass_def)
147
- declare_derived_fields(compiled_klass, klass_def)
148
- register(name, compiled_klass)
149
- end
150
-
151
- alias compile_data_type compile_class
152
- def build_compiled_class(def_obj)
153
- all_attrs = build_attributes(def_obj)
154
- immediate, deferred = all_attrs.partition do |(_, raw_type, type, _)|
155
- type != :string || TYPE_MAP.key?(raw_type) || raw_type.start_with?('reference:(')
156
- end
157
-
158
- compiled_klass = Class.new(Lutaml::Model::Serializable) do
159
- immediate.each do |attr_name, _raw, type, options|
160
- attribute attr_name, type, options
161
- end
162
- end
163
- render_nil_map = Array(def_obj.attributes).to_h do |a|
164
- [a.name.to_sym, declared_render_nil(a)]
165
- end.compact
166
- unless render_nil_map.empty?
167
- compiled_klass.class_eval do
168
- @lml_render_nil = render_nil_map
169
-
170
- class << self
171
- attr_reader :lml_render_nil
172
- end
173
- end
174
- apply_render_nil_mappings(compiled_klass, render_nil_map)
175
- end
176
-
177
- name = def_obj.name.to_s
178
- @forward_refs[name] = deferred unless deferred.empty?
179
- compiled_klass
180
- end
181
-
182
- def build_attributes(klass_def)
183
- Array(klass_def.attributes).map do |attr|
184
- attr_name = attr.name.to_sym
185
- raw_type = resolve_values_type(klass_def, attr)
186
- type = resolve_type(raw_type)
187
- options = build_options(attr)
188
- [attr_name, raw_type, type, options]
189
- end
190
- end
191
-
192
- def resolve_type(type_name)
193
- return TYPE_MAP[type_name] if TYPE_MAP.key?(type_name)
194
- return :string if type_name.start_with?('reference:(')
195
- return @compiled[type_name] if @compiled.key?(type_name)
196
-
197
- :string
198
- end
199
-
200
- def build_options(attr)
201
- declared = declared_attribute_options(attr)
202
- options = {}
203
- card = attr.cardinality
204
- unless card
205
- # LML attributes without an explicit cardinality are optional (0..1)
206
- options[:default] = declared[:default]
207
- return options
208
- end
209
-
210
- min = parse_cardinality_value(card.min)
211
- max = parse_cardinality_value(card.max)
212
-
213
- collection = (max && (max > 1 || max == Float::INFINITY)) ||
214
- (max.nil? && min && min > 1)
215
- if collection
216
- options[:collection] = true
217
- elsif min.zero?
218
- options[:default] = nil
219
- end
220
- # a declared default literal wins over the absent-marker
221
- options[:default] = declared[:default] if declared.key?(:default)
222
- options
223
- end
224
-
225
- # L7b: default <literal> and render_nil true|false ride the
226
- # keyword-attribute properties (bare name-value lines). Defaults
227
- # fire only on ABSENT input; render_nil mirrors lutaml-model.
228
- def declared_attribute_options(attr)
229
- options = {}
230
- Array(attr.properties).each do |prop|
231
- next unless prop.name.to_s == 'default'
232
-
233
- value = prop.value
234
- value = value[:string] if value.is_a?(Hash) && value.key?(:string)
235
- options[:default] = value&.to_s
236
- end
237
- options
238
- end
239
-
240
- # render_nil is a lutaml-model MAPPING option, not an attribute
241
- # option: collect the declaration for the mapping passes
242
- def declared_render_nil(attr)
243
- prop = Array(attr.properties).find { |prop| prop.name.to_s == 'render_nil' }
244
- prop ? prop.value.to_s == 'true' : nil
245
- end
246
-
247
- def parse_cardinality_value(val)
248
- return nil if val.nil?
249
- return Float::INFINITY if UNBOUNDED_TOKENS.include?(val.to_s)
250
- return val.to_i if val.to_s.match?(/\A\d+\z/)
251
-
252
- message = "Unrecognized cardinality token: #{val.inspect}"
253
- raise ValidationError.new(
254
- message,
255
- diagnostic: Diagnostic.build('contract/LML-C04', message: message),
256
- )
257
- end
258
-
259
- def declare_derived_fields(compiled_klass, def_obj)
260
- return unless def_obj.is_a?(UmlClass) || def_obj.is_a?(DataType)
261
-
262
- derived = Array(def_obj.derived_fields)
263
- return if derived.empty?
264
-
265
- compiled_klass.class_eval do
266
- @lml_derived_fields = derived.map(&:name).map(&:to_sym)
267
- def self.derived_fields
268
- @lml_derived_fields
269
- end
270
- end
271
- derived.each do |field|
272
- compiled_klass.attribute field.name.to_sym, resolve_type(field.type.to_s)
273
- end
274
- end
275
-
276
- def artifact_path_for(reference)
277
- mapped = @artifact_paths && @artifact_paths[reference]
278
- return mapped if mapped && File.exist?(mapped.to_s)
279
- return reference if File.exist?(reference)
280
-
281
- nil
282
- end
283
-
284
- # Emit KV mappings carrying render_nil for the declared
285
- # attributes (yaml/json round-trips honor them)
286
- def apply_render_nil_mappings(compiled_klass, render_nil_map)
287
- %i[yaml json].each do |fmt|
288
- compiled_klass.public_send(fmt) do |mapping|
289
- render_nil_map.each do |name, flag|
290
- mapping.map name.to_s, to: name, render_nil: flag
291
- end
292
- end
293
- end
294
- end
295
-
296
- def register(name, klass)
297
- @compiled[name] = klass
298
- return name_anonymous_class(klass, name) unless @namespace
299
-
300
- namespace_module.const_set(name, klass)
301
- end
302
-
303
- # Without a target namespace the class stays anonymous, and
304
- # lutaml-model's schema generators need a class name for $defs/$ref.
305
- def name_anonymous_class(klass, name)
306
- klass.define_singleton_method(:name) { name }
307
- end
308
-
309
- def namespace_module
310
- return @namespace if @namespace.is_a?(Module)
311
-
312
- @namespace_module ||= begin
313
- chain = @namespace.to_s.split('::')
314
- chain.reduce(Object) do |parent, name|
315
- parent.const_get(name)
316
- rescue NameError
317
- parent.const_set(name, Module.new)
318
- end
319
- end
320
- end
321
- end
322
- end
323
- end
@@ -1,10 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Lutaml
4
- module Lml
5
- class Action < Lutaml::Model::Serializable
6
- attribute :verb, :string
7
- attribute :direction, :string
8
- end
9
- end
10
- end
@@ -1,29 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Lutaml
4
- module Lml
5
- # A relationship between two class ends.
6
- class Association < Lutaml::Model::Serializable
7
- include Lutaml::Lml::Positioned
8
-
9
- # From TopElement
10
- attribute :name, :string
11
- attribute :definition, Lutaml::Lml::Types::TextType
12
- attribute :keyword, :string
13
- attribute :stereotype, :string, collection: true, default: -> { [] }
14
- attribute :visibility, :string, default: "public"
15
-
16
- # From Association
17
- attribute :owner_end, :string
18
- attribute :owner_end_attribute_name, :string
19
- attribute :owner_end_cardinality, "Lutaml::Lml::Cardinality"
20
- attribute :owner_end_type, :string
21
- attribute :member_end, :string
22
- attribute :member_end_attribute_name, :string
23
- attribute :member_end_cardinality, "Lutaml::Lml::Cardinality"
24
- attribute :member_end_type, :string
25
- attribute :static, :string
26
- attribute :action, "Lutaml::Lml::Action"
27
- end
28
- end
29
- end
@@ -1,10 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Lutaml
4
- module Lml
5
- class Cardinality < Lutaml::Model::Serializable
6
- attribute :min, :string
7
- attribute :max, :string
8
- end
9
- end
10
- end
@@ -1,11 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Lutaml
4
- module Lml
5
- class Collection < Lutaml::Model::Serializable
6
- attribute :name, :string
7
- attribute :includes, :string, collection: true
8
- attribute :validations, :string, collection: true
9
- end
10
- end
11
- end
@@ -1,23 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Lutaml
4
- module Lml
5
- # A named constraint on a class.
6
- class Constraint < Lutaml::Model::Serializable
7
- include Lutaml::Lml::Positioned
8
-
9
- # From TopElement
10
- attribute :name, :string
11
- attribute :definition, Lutaml::Lml::Types::TextType
12
- attribute :keyword, :string
13
- attribute :stereotype, :string, collection: true, default: -> { [] }
14
- attribute :visibility, :string, default: "public"
15
-
16
- # From Constraint
17
- attribute :body, :string
18
- attribute :type, :string
19
- attribute :weight, :string
20
- attribute :status, :string
21
- end
22
- end
23
- end
@@ -1,41 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Lutaml
4
- module Lml
5
- # A user-defined data type declaration.
6
- class DataType < Lutaml::Model::Serializable
7
- include Lutaml::Lml::Positioned
8
-
9
- # From TopElement
10
- attribute :name, :string
11
- attribute :wire_mappings, "Lutaml::Lml::Mapping", collection: true, default: -> { [] }
12
- attribute :derived_fields, "Lutaml::Lml::DerivedField", collection: true, default: -> { [] }
13
- attribute :serialization_mappings, "Lutaml::Lml::SerializationMapping", collection: true, default: -> { [] }
14
- attribute :definition, Lutaml::Lml::Types::TextType
15
- attribute :keyword, :string, default: "dataType"
16
- attribute :stereotype, :string, collection: true, default: -> { [] }
17
- attribute :visibility, :string, default: "public"
18
-
19
- # From UmlClassifier
20
- attribute :is_abstract, :boolean, default: false
21
-
22
- # From DataType
23
- attribute :nested_classifier, :string, collection: true, default: -> { [] }
24
- attribute :type, :string
25
- attribute :attributes, "Lutaml::Lml::TopElementAttribute", collection: true
26
- attribute :modifier, :string
27
- attribute :constraints, "Lutaml::Lml::Constraint", collection: true
28
- attribute :operations, "Lutaml::Lml::Operation", collection: true
29
- attribute :data_types, "Lutaml::Lml::DataType", collection: true
30
- attribute :associations, "Lutaml::Lml::Association", collection: true
31
-
32
- def self.entity_type
33
- :data_types
34
- end
35
-
36
- def self.classifiable?
37
- true
38
- end
39
- end
40
- end
41
- end
@@ -1,14 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Lutaml
4
- module Lml
5
- # A derived-field declaration: existence + type only. The
6
- # computation is bound by the binder from the grammar artifact's
7
- # derive specs — LML never defines computation.
8
- # derive urn: String
9
- class DerivedField < Lutaml::Model::Serializable
10
- attribute :name, :string
11
- attribute :type, :string
12
- end
13
- end
14
- end
@@ -1,20 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Lutaml
4
- module Lml
5
- # A diagram declaration.
6
- class Diagram < Lutaml::Model::Serializable
7
- include Lutaml::Lml::Positioned
8
-
9
- attribute :name, :string
10
- attribute :definition, Lutaml::Lml::Types::TextType
11
- attribute :keyword, :string
12
- attribute :stereotype, :string, collection: true, default: -> { [] }
13
- attribute :visibility, :string, default: "public"
14
-
15
- attribute :package_id, :string
16
- attribute :package_name, :string
17
- attribute :diagram_type, :string
18
- end
19
- end
20
- end
@@ -1,84 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Lutaml
4
- module Lml
5
- # The parsed LML document model.
6
- class Document < Lutaml::Model::Serializable
7
- include Lutaml::Lml::Positioned
8
-
9
- # Non-serialized navigation index (definitions and uses).
10
- def symbols
11
- @symbols ||= SymbolIndex.new(self)
12
- end
13
-
14
- # Core attributes
15
- attribute :name, :string
16
- attribute :lml_version, :string
17
- attribute :title, :string
18
- attribute :caption, :string
19
- attribute :groups, "Lutaml::Lml::Group", collection: true, default: -> { [] }
20
- attribute :fidelity, "Lutaml::Lml::Fidelity"
21
- attribute :fontname, :string
22
- attribute :comments, :string, collection: true, default: -> { [] }
23
-
24
- attribute :classes, "Lutaml::Lml::UmlClass", collection: true, default: -> { [] }
25
- attribute :data_types, "Lutaml::Lml::DataType", collection: true, default: -> { [] }
26
- attribute :enums, "Lutaml::Lml::Enum", collection: true, default: -> { [] }
27
- attribute :packages, "Lutaml::Lml::Package", collection: true, default: -> { [] }
28
- attribute :namespaces, "Lutaml::Lml::Namespace", collection: true, default: -> { [] }
29
- # `models <Name> version "x.y.z"` headers: model name -> declared
30
- # version (issue #16, the co-release identity line).
31
- attribute :model_versions, :hash, default: -> { {} }
32
- attribute :serialization_mappings, "Lutaml::Lml::SerializationMapping", collection: true, default: -> { [] }
33
- attribute :primitives, "Lutaml::Lml::PrimitiveType", collection: true, default: -> { [] }
34
- attribute :associations, "Lutaml::Lml::Association", collection: true, default: -> { [] }
35
- attribute :diagrams, "Lutaml::Lml::Diagram", collection: true, default: -> { [] }
36
-
37
- # LML-specific. instance/instances/fidelity/show_filter/hide_filter
38
- # are deliberately default-less: nil means "absent".
39
- attribute :instance, "Lutaml::Lml::Instance"
40
- attribute :requires, :string, collection: true, default: -> { [] }
41
- attribute :instances, "Lutaml::Lml::InstanceCollection"
42
-
43
- # Repeated `instances` blocks accumulate (issue #17): instances,
44
- # imports, exports and collections concat; a duplicate collection
45
- # name is an error (same name is a mistake, distinct names intent).
46
- def instances=(collection)
47
- collection = Lutaml::Lml::InstanceCollection.new(**collection) if collection.is_a?(Hash)
48
- if @instances.nil? || (@instances.instances.empty? && @instances.imports.empty? &&
49
- @instances.exports.empty? && @instances.collections.empty?)
50
- @instances = collection
51
- else
52
- merge_instances(collection)
53
- end
54
- end
55
-
56
- def merge_instances(incoming)
57
- names = @instances.collections.map(&:name)
58
- incoming.collections.each do |collection|
59
- raise Lutaml::Lml::Error, "duplicate collection name '#{collection.name}'" if names.include?(collection.name)
60
- end
61
- @instances.instances.concat(incoming.instances)
62
- @instances.imports.concat(incoming.imports)
63
- @instances.exports.concat(incoming.exports)
64
- @instances.collections.concat(incoming.collections)
65
- end
66
- attribute :view_imports, "Lutaml::Lml::ViewImport", collection: true, default: -> { [] }
67
- attribute :show_filter, "Lutaml::Lml::ViewFilter"
68
- attribute :hide_filter, "Lutaml::Lml::ViewFilter"
69
-
70
- # All class-like entities on the document. Used by resolvers and
71
- # formatters that need to walk every classifiable type without
72
- # caring which collection holds it.
73
- def all_classes
74
- EntityTypes.all.flat_map { |type| public_send(type.entity_type) }
75
- end
76
-
77
- # Class-like entities that can own associations. Excludes enums
78
- # (which have no attributes/associations of their own).
79
- def classifiable_classes
80
- EntityTypes.classifiable.flat_map { |type| public_send(type.entity_type) }
81
- end
82
- end
83
- end
84
- end
@@ -1,38 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Lutaml
4
- module Lml
5
- # An enumeration declaration with its value members.
6
- class Enum < Lutaml::Model::Serializable
7
- include Lutaml::Lml::Positioned
8
-
9
- # From TopElement
10
- attribute :name, :string
11
- attribute :definition, Lutaml::Lml::Types::TextType
12
- attribute :keyword, :string, default: "enumeration"
13
- attribute :stereotype, :string, collection: true, default: -> { [] }
14
- attribute :visibility, :string, default: "public"
15
-
16
- # From UmlClassifier
17
- attribute :is_abstract, :boolean, default: false
18
-
19
- # From Enum
20
- attribute :attributes, "Lutaml::Lml::TopElementAttribute", collection: true,
21
- default: -> { [] }
22
- attribute :modifier, :string
23
- attribute :member_fields, "Lutaml::Lml::MemberField", collection: true, default: -> { [] }
24
- attribute :from_table_name, :string
25
- attribute :from_table_artifact, :string
26
- attribute :operations, "Lutaml::Lml::Operation", collection: true, default: -> { [] }
27
- attribute :values, "Lutaml::Lml::Value", collection: true, default: -> { [] }
28
-
29
- def self.entity_type
30
- :enums
31
- end
32
-
33
- def self.classifiable?
34
- false
35
- end
36
- end
37
- end
38
- end
@@ -1,10 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Lutaml
4
- module Lml
5
- class Fidelity < Lutaml::Model::Serializable
6
- attribute :hideMembers, :boolean
7
- attribute :hideOtherClasses, :boolean
8
- end
9
- end
10
- end
@@ -1,11 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Lutaml
4
- module Lml
5
- class Group < Lutaml::Model::Serializable
6
- attribute :id, :string
7
- attribute :values, :string, collection: true
8
- attribute :groups, "Lutaml::Lml::Group", collection: true
9
- end
10
- end
11
- end
@@ -1,26 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Lutaml
4
- module Lml
5
- # An instance with attribute assignments.
6
- class Instance < Lutaml::Model::Serializable
7
- include Lutaml::Lml::Positioned
8
-
9
- attribute :name, :string
10
- attribute :type, :string
11
- attribute :isa, :string
12
- attribute :attributes, "Lutaml::Lml::TopElementAttribute", collection: true
13
- attribute :instance, "Lutaml::Lml::Instance"
14
- attribute :template, "Lutaml::Lml::TopElementAttribute", collection: true
15
- attribute :parent, :string
16
-
17
- def each_attribute
18
- return enum_for(:each_attribute) unless block_given?
19
-
20
- Array(attributes).each do |attr|
21
- yield attr.name, attr.value, Array(attr.instances)
22
- end
23
- end
24
- end
25
- end
26
- end
@@ -1,16 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Lutaml
4
- module Lml
5
- # A named instances collection with its instances and imports/exports.
6
- class InstanceCollection < Lutaml::Model::Serializable
7
- include Lutaml::Lml::Positioned
8
-
9
- attribute :name, :string
10
- attribute :instances, "Lutaml::Lml::Instance", collection: true, default: []
11
- attribute :imports, "Lutaml::Lml::InstancesImport", collection: true, default: []
12
- attribute :exports, "Lutaml::Lml::InstancesExport", collection: true, default: []
13
- attribute :collections, "Lutaml::Lml::Collection", collection: true, default: []
14
- end
15
- end
16
- end