lutaml-lml 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/lib/lutaml/lml/association_label_resolver.rb +52 -0
- data/lib/lutaml/lml/cli.rb +262 -0
- data/lib/lutaml/lml/data_processor/attribute_processing.rb +81 -0
- data/lib/lutaml/lml/data_processor/collection_processing.rb +37 -0
- data/lib/lutaml/lml/data_processor/instance_processing.rb +63 -0
- data/lib/lutaml/lml/data_processor/value_processing.rb +98 -0
- data/lib/lutaml/lml/data_processor/view_processing.rb +25 -0
- data/lib/lutaml/lml/data_processor.rb +49 -0
- data/lib/lutaml/lml/document_builder.rb +139 -0
- data/lib/lutaml/lml/executor/adapter_helpers.rb +45 -0
- data/lib/lutaml/lml/executor/condition_evaluator.rb +169 -0
- data/lib/lutaml/lml/executor/csv_adapter.rb +88 -0
- data/lib/lutaml/lml/executor/format_adapter.rb +54 -0
- data/lib/lutaml/lml/executor/xml_adapter.rb +102 -0
- data/lib/lutaml/lml/executor.rb +89 -0
- data/lib/lutaml/lml/format/adapter/document.rb +11 -0
- data/lib/lutaml/lml/format/adapter/mapping.rb +19 -0
- data/lib/lutaml/lml/format/adapter/standard_adapter.rb +127 -0
- data/lib/lutaml/lml/format/adapter/transform.rb +11 -0
- data/lib/lutaml/lml/format.rb +29 -0
- data/lib/lutaml/lml/formatter/base.rb +79 -0
- data/lib/lutaml/lml/formatter/graphviz/document_formatter.rb +89 -0
- data/lib/lutaml/lml/formatter/graphviz/html_builder.rb +72 -0
- data/lib/lutaml/lml/formatter/graphviz/node_formatter.rb +74 -0
- data/lib/lutaml/lml/formatter/graphviz/relationship_formatter.rb +130 -0
- data/lib/lutaml/lml/formatter/graphviz.rb +90 -0
- data/lib/lutaml/lml/formatter.rb +8 -0
- data/lib/lutaml/lml/grammar/concerns/associations.rb +76 -0
- data/lib/lutaml/lml/grammar/concerns/attributes.rb +126 -0
- data/lib/lutaml/lml/grammar/concerns/data_structures.rb +84 -0
- data/lib/lutaml/lml/grammar/concerns/definitions.rb +222 -0
- data/lib/lutaml/lml/grammar/concerns/instance_rules.rb +59 -0
- data/lib/lutaml/lml/grammar/concerns/primitives.rb +89 -0
- data/lib/lutaml/lml/grammar/concerns/view_rules.rb +34 -0
- data/lib/lutaml/lml/grammar/concerns.rb +17 -0
- data/lib/lutaml/lml/grammar/core.rb +71 -0
- data/lib/lutaml/lml/grammar/full.rb +12 -0
- data/lib/lutaml/lml/grammar/instances.rb +38 -0
- data/lib/lutaml/lml/grammar.rb +12 -0
- data/lib/lutaml/lml/has_attributes.rb +14 -0
- data/lib/lutaml/lml/import_resolver.rb +89 -0
- data/lib/lutaml/lml/layout/engine.rb +17 -0
- data/lib/lutaml/lml/layout/graph_viz_engine.rb +19 -0
- data/lib/lutaml/lml/layout.rb +8 -0
- data/lib/lutaml/lml/model_compiler.rb +325 -0
- data/lib/lutaml/lml/models/action.rb +10 -0
- data/lib/lutaml/lml/models/association.rb +26 -0
- data/lib/lutaml/lml/models/cardinality.rb +10 -0
- data/lib/lutaml/lml/models/collection.rb +11 -0
- data/lib/lutaml/lml/models/constraint.rb +20 -0
- data/lib/lutaml/lml/models/data_type.rb +31 -0
- data/lib/lutaml/lml/models/diagram.rb +17 -0
- data/lib/lutaml/lml/models/document.rb +45 -0
- data/lib/lutaml/lml/models/enum.rb +28 -0
- data/lib/lutaml/lml/models/fidelity.rb +10 -0
- data/lib/lutaml/lml/models/group.rb +11 -0
- data/lib/lutaml/lml/models/instance.rb +13 -0
- data/lib/lutaml/lml/models/instance_collection.rb +12 -0
- data/lib/lutaml/lml/models/instances_export.rb +10 -0
- data/lib/lutaml/lml/models/instances_import.rb +11 -0
- data/lib/lutaml/lml/models/operation.rb +23 -0
- data/lib/lutaml/lml/models/operation_parameter.rb +11 -0
- data/lib/lutaml/lml/models/package.rb +22 -0
- data/lib/lutaml/lml/models/primitive_type.rb +26 -0
- data/lib/lutaml/lml/models/top_element_attribute.rb +31 -0
- data/lib/lutaml/lml/models/uml_class.rb +84 -0
- data/lib/lutaml/lml/models/value.rb +12 -0
- data/lib/lutaml/lml/models/view_filter.rb +11 -0
- data/lib/lutaml/lml/models/view_import.rb +11 -0
- data/lib/lutaml/lml/parser.rb +22 -0
- data/lib/lutaml/lml/pipeline.rb +64 -0
- data/lib/lutaml/lml/preprocessor.rb +56 -0
- data/lib/lutaml/lml/transform.rb +20 -0
- data/lib/lutaml/lml/version.rb +7 -0
- data/lib/lutaml/lml/view_resolver.rb +48 -0
- data/lib/lutaml/lml/yaml_parser.rb +17 -0
- data/lib/lutaml/lml.rb +67 -0
- metadata +178 -0
|
@@ -0,0 +1,325 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Lutaml
|
|
4
|
+
module Lml
|
|
5
|
+
class ModelCompiler
|
|
6
|
+
class ValidationError < Error; end
|
|
7
|
+
|
|
8
|
+
TYPE_MAP = {
|
|
9
|
+
"String" => :string,
|
|
10
|
+
"Integer" => :integer,
|
|
11
|
+
"Boolean" => :boolean,
|
|
12
|
+
"Float" => :float,
|
|
13
|
+
"Date" => :date,
|
|
14
|
+
"date_time" => :date_time,
|
|
15
|
+
"DateTime" => :date_time,
|
|
16
|
+
"Time" => :time,
|
|
17
|
+
"Uri" => :string,
|
|
18
|
+
"Hash" => :hash,
|
|
19
|
+
}.freeze
|
|
20
|
+
|
|
21
|
+
def initialize(namespace: nil)
|
|
22
|
+
@namespace = namespace
|
|
23
|
+
@compiled = {}
|
|
24
|
+
@forward_refs = {}
|
|
25
|
+
@enum_names = Set.new
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def compile(input)
|
|
29
|
+
doc = Pipeline.call(input, resolve: false)
|
|
30
|
+
compile_document(doc)
|
|
31
|
+
@compiled
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def hydrate(input)
|
|
35
|
+
doc = input.is_a?(Document) ? input : Pipeline.call(input, resolve: false)
|
|
36
|
+
compile_document(doc) unless @compiled.any?
|
|
37
|
+
return {} unless doc.instance
|
|
38
|
+
|
|
39
|
+
hydrate_instance(doc.instance)
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def compiled_classes
|
|
43
|
+
@compiled
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def validate(input_or_instance, compiled: nil)
|
|
47
|
+
if compiled
|
|
48
|
+
@compiled = compiled
|
|
49
|
+
elsif input_or_instance.is_a?(String) || input_or_instance.is_a?(IO) || input_or_instance.is_a?(StringIO)
|
|
50
|
+
doc = Pipeline.call(input_or_instance, resolve: false)
|
|
51
|
+
compile_document(doc)
|
|
52
|
+
end
|
|
53
|
+
errors = []
|
|
54
|
+
instance = input_or_instance.is_a?(Lutaml::Lml::Instance) ? input_or_instance : nil
|
|
55
|
+
unless instance
|
|
56
|
+
doc ||= Pipeline.call(input_or_instance, resolve: false)
|
|
57
|
+
instance = doc.instance
|
|
58
|
+
end
|
|
59
|
+
validate_instance(instance, errors) if instance
|
|
60
|
+
errors
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
private
|
|
64
|
+
|
|
65
|
+
def validate_instance(instance, errors, path = "root")
|
|
66
|
+
if instance.instance && Array(instance.attributes).empty?
|
|
67
|
+
validate_instance(instance.instance, errors, "#{path}.instance")
|
|
68
|
+
return
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
attrs = Array(instance.attributes)
|
|
72
|
+
type_attr = attrs.find { |a| a.name == "type" }
|
|
73
|
+
type_name = type_attr ? type_attr.value.to_s : instance.type
|
|
74
|
+
klass = @compiled[type_name]
|
|
75
|
+
unless klass
|
|
76
|
+
errors << "#{path}: unknown type '#{type_name}'"
|
|
77
|
+
return
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
schema_attrs = klass.attributes.keys.map(&:to_s)
|
|
81
|
+
present_attrs = attrs.map(&:name)
|
|
82
|
+
schema_set = schema_attrs.to_set
|
|
83
|
+
present_set = present_attrs.to_set
|
|
84
|
+
|
|
85
|
+
unknown = present_set - schema_set - Set.new(%w[type])
|
|
86
|
+
unknown.each do |name|
|
|
87
|
+
errors << "#{path}.#{name}: attribute not defined on #{type_name}"
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
required = klass.attributes.select do |_k, v|
|
|
91
|
+
!v.collection? && !v.options.key?(:default)
|
|
92
|
+
end.keys.map(&:to_s).to_set
|
|
93
|
+
|
|
94
|
+
missing = required - present_set
|
|
95
|
+
missing.each do |name|
|
|
96
|
+
errors << "#{path}.#{name}: required attribute missing (cardinality min >= 1)"
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
attrs.each do |attr|
|
|
100
|
+
next unless schema_attrs.include?(attr.name)
|
|
101
|
+
attr_def = klass.attributes[attr.name.to_sym]
|
|
102
|
+
next unless attr_def
|
|
103
|
+
|
|
104
|
+
if attr_def.collection? && attr.instances.any?
|
|
105
|
+
attr.instances.each_with_index do |nested, i|
|
|
106
|
+
validate_instance(nested, errors, "#{path}.#{attr.name}[#{i}]")
|
|
107
|
+
end
|
|
108
|
+
end
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
if instance.instance
|
|
112
|
+
validate_instance(instance.instance, errors, "#{path}.instance")
|
|
113
|
+
end
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
def hydrate_instance(instance)
|
|
117
|
+
inner = instance.instance
|
|
118
|
+
return hydrate_instance(inner) if inner && Array(instance.attributes).empty?
|
|
119
|
+
|
|
120
|
+
type_name = resolve_instance_type(instance)
|
|
121
|
+
klass = @compiled[type_name]
|
|
122
|
+
return hydrate_as_untyped(instance, type_name) unless klass
|
|
123
|
+
|
|
124
|
+
attrs = extract_instance_attributes(instance, klass)
|
|
125
|
+
klass.new(**attrs)
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
def resolve_instance_type(instance)
|
|
129
|
+
type_attr = Array(instance.attributes).find { |a| a.name == "type" }
|
|
130
|
+
raw = type_attr ? type_attr.value.to_s : instance.type.to_s
|
|
131
|
+
demodulize(raw)
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
def demodulize(name)
|
|
135
|
+
name.split("::").last.to_s
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
def hydrate_as_untyped(instance, type_name)
|
|
139
|
+
{ _name: type_name, **extract_raw_attributes(instance) }
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
def extract_raw_attributes(instance)
|
|
143
|
+
Array(instance.attributes).each_with_object({}) do |attr, hash|
|
|
144
|
+
if attr.instances.any?
|
|
145
|
+
hash[attr.name.to_sym] = attr.instances.map { |i| hydrate_instance(i) }
|
|
146
|
+
elsif attr.value.is_a?(Array)
|
|
147
|
+
hash[attr.name.to_sym] = attr.value
|
|
148
|
+
elsif !attr.value.nil?
|
|
149
|
+
hash[attr.name.to_sym] = attr.value
|
|
150
|
+
end
|
|
151
|
+
end
|
|
152
|
+
end
|
|
153
|
+
|
|
154
|
+
def extract_instance_attributes(instance, klass)
|
|
155
|
+
schema_keys = klass.attributes.keys
|
|
156
|
+
Array(instance.attributes).each_with_object({}) do |attr, hash|
|
|
157
|
+
key = attr.name.to_sym
|
|
158
|
+
next unless schema_keys.include?(key)
|
|
159
|
+
|
|
160
|
+
hash[key] = coerce_attribute_value(attr, klass.attributes[key])
|
|
161
|
+
end
|
|
162
|
+
end
|
|
163
|
+
|
|
164
|
+
def coerce_attribute_value(attr, _attr_def)
|
|
165
|
+
if attr.instances.any?
|
|
166
|
+
attr.instances.map { |i| hydrate_instance(i) }
|
|
167
|
+
elsif attr.value.is_a?(Array)
|
|
168
|
+
attr.value
|
|
169
|
+
elsif !attr.value.nil?
|
|
170
|
+
attr.value
|
|
171
|
+
end
|
|
172
|
+
end
|
|
173
|
+
|
|
174
|
+
def compile_document(doc)
|
|
175
|
+
doc.classes.each { |c| compile_class(c) }
|
|
176
|
+
doc.enums.each { |e| compile_enum(e) }
|
|
177
|
+
doc.data_types.each { |dt| compile_data_type(dt) }
|
|
178
|
+
resolve_forward_references
|
|
179
|
+
apply_xml_mappings
|
|
180
|
+
end
|
|
181
|
+
|
|
182
|
+
def resolve_forward_references
|
|
183
|
+
@forward_refs.each do |class_name, deferred_attrs|
|
|
184
|
+
klass = @compiled[class_name]
|
|
185
|
+
next unless klass
|
|
186
|
+
|
|
187
|
+
deferred_attrs.each do |attr_name, raw_type, _type, options|
|
|
188
|
+
resolved = resolve_type(raw_type)
|
|
189
|
+
klass.attribute attr_name, resolved, **options
|
|
190
|
+
end
|
|
191
|
+
end
|
|
192
|
+
end
|
|
193
|
+
|
|
194
|
+
def compile_class(klass_def)
|
|
195
|
+
name = klass_def.name.to_s
|
|
196
|
+
compiled_klass = build_compiled_class(klass_def)
|
|
197
|
+
register(name, compiled_klass)
|
|
198
|
+
end
|
|
199
|
+
|
|
200
|
+
alias_method :compile_data_type, :compile_class
|
|
201
|
+
|
|
202
|
+
def compile_enum(enum_def)
|
|
203
|
+
name = enum_def.name.to_s
|
|
204
|
+
values = extract_enum_values(enum_def)
|
|
205
|
+
|
|
206
|
+
compiled_klass = Class.new(Lutaml::Model::Serializable) do
|
|
207
|
+
attribute :value, :string, default: values.first.to_s
|
|
208
|
+
|
|
209
|
+
define_method(:to_s) { value }
|
|
210
|
+
end
|
|
211
|
+
|
|
212
|
+
values.each do |val|
|
|
213
|
+
compiled_klass.define_singleton_method(val) do
|
|
214
|
+
new(value: val.to_s)
|
|
215
|
+
end
|
|
216
|
+
end
|
|
217
|
+
|
|
218
|
+
@enum_names << name
|
|
219
|
+
register(name, compiled_klass)
|
|
220
|
+
end
|
|
221
|
+
|
|
222
|
+
# Builds a compiled Serializable subclass from a class or data-type
|
|
223
|
+
# definition: declares attributes and stashes forward-referenced
|
|
224
|
+
# attributes for post-registration resolution.
|
|
225
|
+
def build_compiled_class(def_obj)
|
|
226
|
+
all_attrs = build_attributes(def_obj)
|
|
227
|
+
immediate, deferred = all_attrs.partition do |(_, raw_type, type, _)|
|
|
228
|
+
type != :string || TYPE_MAP.key?(raw_type) || raw_type.start_with?("reference:(")
|
|
229
|
+
end
|
|
230
|
+
|
|
231
|
+
compiled_klass = Class.new(Lutaml::Model::Serializable) do
|
|
232
|
+
immediate.each do |attr_name, _raw, type, options|
|
|
233
|
+
attribute attr_name, type, options
|
|
234
|
+
end
|
|
235
|
+
end
|
|
236
|
+
|
|
237
|
+
name = def_obj.name.to_s
|
|
238
|
+
@forward_refs[name] = deferred unless deferred.empty?
|
|
239
|
+
compiled_klass
|
|
240
|
+
end
|
|
241
|
+
|
|
242
|
+
# Apply a lutaml-model XML mapping to each compiled class so they
|
|
243
|
+
# support from_xml/to_xml. Runs after forward references are resolved
|
|
244
|
+
# so all attributes (immediate + deferred) get element mappings.
|
|
245
|
+
def apply_xml_mappings
|
|
246
|
+
@compiled.each do |name, klass|
|
|
247
|
+
next if @enum_names.include?(name)
|
|
248
|
+
|
|
249
|
+
apply_xml_mapping(klass, name)
|
|
250
|
+
end
|
|
251
|
+
end
|
|
252
|
+
|
|
253
|
+
def apply_xml_mapping(klass, root_name)
|
|
254
|
+
attr_names = klass.attributes.keys
|
|
255
|
+
return if attr_names.empty?
|
|
256
|
+
|
|
257
|
+
klass.xml do |mapping|
|
|
258
|
+
mapping.root(root_name)
|
|
259
|
+
attr_names.each do |attr_name|
|
|
260
|
+
mapping.map_element(attr_name.to_s, to: attr_name)
|
|
261
|
+
end
|
|
262
|
+
end
|
|
263
|
+
end
|
|
264
|
+
|
|
265
|
+
def build_attributes(klass_def)
|
|
266
|
+
Array(klass_def.attributes).map do |attr|
|
|
267
|
+
attr_name = attr.name.to_sym
|
|
268
|
+
raw_type = attr.type.to_s
|
|
269
|
+
type = resolve_type(raw_type)
|
|
270
|
+
options = build_options(attr)
|
|
271
|
+
[attr_name, raw_type, type, options]
|
|
272
|
+
end
|
|
273
|
+
end
|
|
274
|
+
|
|
275
|
+
def resolve_type(type_name)
|
|
276
|
+
if TYPE_MAP.key?(type_name)
|
|
277
|
+
TYPE_MAP[type_name]
|
|
278
|
+
elsif type_name.start_with?("reference:(")
|
|
279
|
+
:string
|
|
280
|
+
elsif @compiled.key?(type_name)
|
|
281
|
+
@compiled[type_name]
|
|
282
|
+
else
|
|
283
|
+
:string
|
|
284
|
+
end
|
|
285
|
+
end
|
|
286
|
+
|
|
287
|
+
def build_options(attr)
|
|
288
|
+
options = {}
|
|
289
|
+
card = attr.cardinality
|
|
290
|
+
return options unless card
|
|
291
|
+
|
|
292
|
+
min = parse_cardinality_value(card.min)
|
|
293
|
+
max = parse_cardinality_value(card.max)
|
|
294
|
+
|
|
295
|
+
if max && (max > 1 || max == Float::INFINITY)
|
|
296
|
+
options[:collection] = true
|
|
297
|
+
elsif max.nil? && min && min > 1
|
|
298
|
+
options[:collection] = true
|
|
299
|
+
elsif min == 0
|
|
300
|
+
options[:default] = nil
|
|
301
|
+
end
|
|
302
|
+
options
|
|
303
|
+
end
|
|
304
|
+
|
|
305
|
+
def parse_cardinality_value(val)
|
|
306
|
+
return nil if val.nil?
|
|
307
|
+
return Float::INFINITY if val == "*" || val == "n"
|
|
308
|
+
val.to_i
|
|
309
|
+
end
|
|
310
|
+
|
|
311
|
+
def extract_enum_values(enum_def)
|
|
312
|
+
enum_def.attributes.map do |attr|
|
|
313
|
+
attr.name.to_s
|
|
314
|
+
end
|
|
315
|
+
end
|
|
316
|
+
|
|
317
|
+
def register(name, klass)
|
|
318
|
+
@compiled[name] = klass
|
|
319
|
+
return unless @namespace
|
|
320
|
+
|
|
321
|
+
@namespace.const_set(name, klass)
|
|
322
|
+
end
|
|
323
|
+
end
|
|
324
|
+
end
|
|
325
|
+
end
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Lutaml
|
|
4
|
+
module Lml
|
|
5
|
+
class Association < Lutaml::Model::Serializable
|
|
6
|
+
# From TopElement
|
|
7
|
+
attribute :name, :string
|
|
8
|
+
attribute :definition, :string
|
|
9
|
+
attribute :keyword, :string
|
|
10
|
+
attribute :stereotype, :string, collection: true, default: -> { [] }
|
|
11
|
+
attribute :visibility, :string, default: "public"
|
|
12
|
+
|
|
13
|
+
# From Association
|
|
14
|
+
attribute :owner_end, :string
|
|
15
|
+
attribute :owner_end_attribute_name, :string
|
|
16
|
+
attribute :owner_end_cardinality, "Lutaml::Lml::Cardinality"
|
|
17
|
+
attribute :owner_end_type, :string
|
|
18
|
+
attribute :member_end, :string
|
|
19
|
+
attribute :member_end_attribute_name, :string
|
|
20
|
+
attribute :member_end_cardinality, "Lutaml::Lml::Cardinality"
|
|
21
|
+
attribute :member_end_type, :string
|
|
22
|
+
attribute :static, :string
|
|
23
|
+
attribute :action, "Lutaml::Lml::Action"
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Lutaml
|
|
4
|
+
module Lml
|
|
5
|
+
class Constraint < Lutaml::Model::Serializable
|
|
6
|
+
# From TopElement
|
|
7
|
+
attribute :name, :string
|
|
8
|
+
attribute :definition, :string
|
|
9
|
+
attribute :keyword, :string
|
|
10
|
+
attribute :stereotype, :string, collection: true, default: -> { [] }
|
|
11
|
+
attribute :visibility, :string, default: "public"
|
|
12
|
+
|
|
13
|
+
# From Constraint
|
|
14
|
+
attribute :body, :string
|
|
15
|
+
attribute :type, :string
|
|
16
|
+
attribute :weight, :string
|
|
17
|
+
attribute :status, :string
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Lutaml
|
|
4
|
+
module Lml
|
|
5
|
+
class DataType < Lutaml::Model::Serializable
|
|
6
|
+
# From TopElement
|
|
7
|
+
attribute :name, :string
|
|
8
|
+
attribute :definition, :string
|
|
9
|
+
attribute :keyword, :string, default: "dataType"
|
|
10
|
+
attribute :stereotype, :string, collection: true, default: -> { [] }
|
|
11
|
+
attribute :visibility, :string, default: "public"
|
|
12
|
+
|
|
13
|
+
# From UmlClassifier
|
|
14
|
+
attribute :is_abstract, :boolean, default: false
|
|
15
|
+
|
|
16
|
+
# From DataType
|
|
17
|
+
attribute :nested_classifier, :string, collection: true, default: -> { [] }
|
|
18
|
+
attribute :type, :string
|
|
19
|
+
attribute :attributes, "Lutaml::Lml::TopElementAttribute", collection: true
|
|
20
|
+
attribute :modifier, :string
|
|
21
|
+
attribute :constraints, "Lutaml::Lml::Constraint", collection: true
|
|
22
|
+
attribute :operations, "Lutaml::Lml::Operation", collection: true
|
|
23
|
+
attribute :data_types, "Lutaml::Lml::DataType", collection: true
|
|
24
|
+
attribute :associations, "Lutaml::Lml::Association", collection: true
|
|
25
|
+
|
|
26
|
+
def self.entity_type
|
|
27
|
+
:data_types
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Lutaml
|
|
4
|
+
module Lml
|
|
5
|
+
class Diagram < Lutaml::Model::Serializable
|
|
6
|
+
attribute :name, :string
|
|
7
|
+
attribute :definition, :string
|
|
8
|
+
attribute :keyword, :string
|
|
9
|
+
attribute :stereotype, :string, collection: true, default: -> { [] }
|
|
10
|
+
attribute :visibility, :string, default: "public"
|
|
11
|
+
|
|
12
|
+
attribute :package_id, :string
|
|
13
|
+
attribute :package_name, :string
|
|
14
|
+
attribute :diagram_type, :string
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Lutaml
|
|
4
|
+
module Lml
|
|
5
|
+
class Document < Lutaml::Model::Serializable
|
|
6
|
+
# Core attributes
|
|
7
|
+
attribute :name, :string
|
|
8
|
+
attribute :title, :string
|
|
9
|
+
attribute :caption, :string
|
|
10
|
+
attribute :groups, "Lutaml::Lml::Group", collection: true
|
|
11
|
+
attribute :fidelity, "Lutaml::Lml::Fidelity"
|
|
12
|
+
attribute :fontname, :string
|
|
13
|
+
attribute :comments, :string, collection: true
|
|
14
|
+
|
|
15
|
+
attribute :classes, "Lutaml::Lml::UmlClass", collection: true, default: -> { [] }
|
|
16
|
+
attribute :data_types, "Lutaml::Lml::DataType", collection: true, default: -> { [] }
|
|
17
|
+
attribute :enums, "Lutaml::Lml::Enum", collection: true, default: -> { [] }
|
|
18
|
+
attribute :packages, "Lutaml::Lml::Package", collection: true, default: -> { [] }
|
|
19
|
+
attribute :primitives, "Lutaml::Lml::PrimitiveType", collection: true, default: -> { [] }
|
|
20
|
+
attribute :associations, "Lutaml::Lml::Association", collection: true, default: -> { [] }
|
|
21
|
+
attribute :diagrams, "Lutaml::Lml::Diagram", collection: true, default: -> { [] }
|
|
22
|
+
|
|
23
|
+
# LML-specific
|
|
24
|
+
attribute :instance, "Lutaml::Lml::Instance"
|
|
25
|
+
attribute :requires, :string, collection: true
|
|
26
|
+
attribute :instances, "Lutaml::Lml::InstanceCollection"
|
|
27
|
+
attribute :view_imports, "Lutaml::Lml::ViewImport", collection: true
|
|
28
|
+
attribute :show_filter, "Lutaml::Lml::ViewFilter"
|
|
29
|
+
attribute :hide_filter, "Lutaml::Lml::ViewFilter"
|
|
30
|
+
|
|
31
|
+
# All class-like entities on the document. Used by resolvers and
|
|
32
|
+
# formatters that need to walk every classifiable type without
|
|
33
|
+
# caring which collection holds it.
|
|
34
|
+
def all_classes
|
|
35
|
+
classes + enums + data_types + primitives
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
# Class-like entities that can own associations. Excludes enums
|
|
39
|
+
# (which have no attributes/associations of their own).
|
|
40
|
+
def classifiable_classes
|
|
41
|
+
classes + data_types + primitives
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Lutaml
|
|
4
|
+
module Lml
|
|
5
|
+
class Enum < Lutaml::Model::Serializable
|
|
6
|
+
# From TopElement
|
|
7
|
+
attribute :name, :string
|
|
8
|
+
attribute :definition, :string
|
|
9
|
+
attribute :keyword, :string, default: "enumeration"
|
|
10
|
+
attribute :stereotype, :string, collection: true, default: -> { [] }
|
|
11
|
+
attribute :visibility, :string, default: "public"
|
|
12
|
+
|
|
13
|
+
# From UmlClassifier
|
|
14
|
+
attribute :is_abstract, :boolean, default: false
|
|
15
|
+
|
|
16
|
+
# From Enum
|
|
17
|
+
attribute :attributes, "Lutaml::Lml::TopElementAttribute", collection: true,
|
|
18
|
+
default: -> { [] }
|
|
19
|
+
attribute :modifier, :string
|
|
20
|
+
attribute :operations, "Lutaml::Lml::Operation", collection: true, default: -> { [] }
|
|
21
|
+
attribute :values, "Lutaml::Lml::Value", collection: true, default: -> { [] }
|
|
22
|
+
|
|
23
|
+
def self.entity_type
|
|
24
|
+
:enums
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Lutaml
|
|
4
|
+
module Lml
|
|
5
|
+
class Instance < Lutaml::Model::Serializable
|
|
6
|
+
attribute :type, :string
|
|
7
|
+
attribute :attributes, "Lutaml::Lml::TopElementAttribute", collection: true
|
|
8
|
+
attribute :instance, "Lutaml::Lml::Instance"
|
|
9
|
+
attribute :template, "Lutaml::Lml::TopElementAttribute", collection: true
|
|
10
|
+
attribute :parent, :string
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Lutaml
|
|
4
|
+
module Lml
|
|
5
|
+
class InstanceCollection < Lutaml::Model::Serializable
|
|
6
|
+
attribute :instances, "Lutaml::Lml::Instance", collection: true, default: []
|
|
7
|
+
attribute :imports, "Lutaml::Lml::InstancesImport", collection: true, default: []
|
|
8
|
+
attribute :exports, "Lutaml::Lml::InstancesExport", collection: true, default: []
|
|
9
|
+
attribute :collections, "Lutaml::Lml::Collection", default: []
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
end
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Lutaml
|
|
4
|
+
module Lml
|
|
5
|
+
class InstancesImport < Lutaml::Model::Serializable
|
|
6
|
+
attribute :format_type, :string
|
|
7
|
+
attribute :file, :string
|
|
8
|
+
attribute :attributes, "Lutaml::Lml::TopElementAttribute", collection: true, default: []
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Lutaml
|
|
4
|
+
module Lml
|
|
5
|
+
class Operation < Lutaml::Model::Serializable
|
|
6
|
+
# From TopElement
|
|
7
|
+
attribute :name, :string
|
|
8
|
+
attribute :definition, :string
|
|
9
|
+
attribute :keyword, :string
|
|
10
|
+
attribute :stereotype, :string, collection: true, default: -> { [] }
|
|
11
|
+
attribute :visibility, :string, default: "public"
|
|
12
|
+
|
|
13
|
+
# From Operation
|
|
14
|
+
attribute :id, :string
|
|
15
|
+
attribute :return_type, :string
|
|
16
|
+
attribute :parameter_type, :string
|
|
17
|
+
attribute :is_static, :boolean, default: false
|
|
18
|
+
attribute :is_abstract, :boolean, default: false
|
|
19
|
+
attribute :owned_parameter, "Lutaml::Lml::OperationParameter", collection: true,
|
|
20
|
+
default: -> { [] }
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Lutaml
|
|
4
|
+
module Lml
|
|
5
|
+
class Package < Lutaml::Model::Serializable
|
|
6
|
+
# From TopElement
|
|
7
|
+
attribute :name, :string
|
|
8
|
+
attribute :definition, :string
|
|
9
|
+
attribute :keyword, :string
|
|
10
|
+
attribute :stereotype, :string, collection: true, default: -> { [] }
|
|
11
|
+
attribute :visibility, :string, default: "public"
|
|
12
|
+
|
|
13
|
+
# From Package
|
|
14
|
+
attribute :contents, :string, collection: true, default: -> { [] }
|
|
15
|
+
attribute :classes, "Lutaml::Lml::UmlClass", collection: true, default: -> { [] }
|
|
16
|
+
attribute :enums, "Lutaml::Lml::Enum", collection: true, default: -> { [] }
|
|
17
|
+
attribute :data_types, "Lutaml::Lml::DataType", collection: true, default: -> { [] }
|
|
18
|
+
attribute :packages, "Lutaml::Lml::Package", collection: true, default: -> { [] }
|
|
19
|
+
attribute :diagrams, "Lutaml::Lml::Diagram", collection: true, default: -> { [] }
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|