lutaml 0.7.7 → 0.8.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (112) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/rake.yml +1 -1
  3. data/.gitignore +7 -6
  4. data/.rubocop.yml +1 -0
  5. data/LUTAML.adoc +372 -0
  6. data/Makefile +2 -0
  7. data/bin/console +5 -0
  8. data/bin/folder_yaml2lutaml.sh +6 -0
  9. data/bin/plantuml2lutaml +59 -0
  10. data/bin/yaml2lutaml +144 -0
  11. data/exe/lutaml-sysml +20 -0
  12. data/exe/lutaml-wsd2uml +59 -0
  13. data/exe/lutaml-yaml2uml +144 -0
  14. data/lib/lutaml/express/README.adoc +55 -0
  15. data/lib/lutaml/express/parsers/exp.rb +21 -0
  16. data/lib/lutaml/express/version.rb +7 -0
  17. data/lib/lutaml/express.rb +9 -0
  18. data/lib/lutaml/parser.rb +7 -0
  19. data/lib/lutaml/sysml/README.md +40 -0
  20. data/lib/lutaml/sysml/allocate.rb +8 -0
  21. data/lib/lutaml/sysml/allocated.rb +7 -0
  22. data/lib/lutaml/sysml/binding_connector.rb +7 -0
  23. data/lib/lutaml/sysml/block.rb +27 -0
  24. data/lib/lutaml/sysml/constraint_block.rb +12 -0
  25. data/lib/lutaml/sysml/copy.rb +6 -0
  26. data/lib/lutaml/sysml/derive_requirement.rb +7 -0
  27. data/lib/lutaml/sysml/nested_connector_end.rb +11 -0
  28. data/lib/lutaml/sysml/refine.rb +7 -0
  29. data/lib/lutaml/sysml/requirement.rb +34 -0
  30. data/lib/lutaml/sysml/requirement_related.rb +7 -0
  31. data/lib/lutaml/sysml/satisfy.rb +7 -0
  32. data/lib/lutaml/sysml/test_case.rb +22 -0
  33. data/lib/lutaml/sysml/trace.rb +7 -0
  34. data/lib/lutaml/sysml/verify.rb +6 -0
  35. data/lib/lutaml/sysml/version.rb +5 -0
  36. data/lib/lutaml/sysml/xmi_file.rb +417 -0
  37. data/lib/lutaml/sysml.rb +10 -0
  38. data/lib/lutaml/uml/README.adoc +44 -0
  39. data/lib/lutaml/uml/abstraction.rb +11 -0
  40. data/lib/lutaml/uml/activity.rb +11 -0
  41. data/lib/lutaml/uml/actor.rb +19 -0
  42. data/lib/lutaml/uml/association.rb +43 -0
  43. data/lib/lutaml/uml/behavior.rb +11 -0
  44. data/lib/lutaml/uml/class.rb +83 -0
  45. data/lib/lutaml/uml/classifier.rb +11 -0
  46. data/lib/lutaml/uml/connector.rb +21 -0
  47. data/lib/lutaml/uml/constraint.rb +12 -0
  48. data/lib/lutaml/uml/constructor_end.rb +16 -0
  49. data/lib/lutaml/uml/data_type.rb +75 -0
  50. data/lib/lutaml/uml/dependency.rb +21 -0
  51. data/lib/lutaml/uml/diagram.rb +8 -0
  52. data/lib/lutaml/uml/document.rb +81 -0
  53. data/lib/lutaml/uml/enum.rb +45 -0
  54. data/lib/lutaml/uml/event.rb +12 -0
  55. data/lib/lutaml/uml/final_state.rb +11 -0
  56. data/lib/lutaml/uml/formatter/base.rb +67 -0
  57. data/lib/lutaml/uml/formatter/graphviz.rb +334 -0
  58. data/lib/lutaml/uml/formatter.rb +21 -0
  59. data/lib/lutaml/uml/has_attributes.rb +14 -0
  60. data/lib/lutaml/uml/has_members.rb +30 -0
  61. data/lib/lutaml/uml/instance.rb +17 -0
  62. data/lib/lutaml/uml/model.rb +13 -0
  63. data/lib/lutaml/uml/node/base.rb +21 -0
  64. data/lib/lutaml/uml/node/class_node.rb +57 -0
  65. data/lib/lutaml/uml/node/class_relationship.rb +14 -0
  66. data/lib/lutaml/uml/node/document.rb +18 -0
  67. data/lib/lutaml/uml/node/field.rb +34 -0
  68. data/lib/lutaml/uml/node/has_name.rb +15 -0
  69. data/lib/lutaml/uml/node/has_type.rb +15 -0
  70. data/lib/lutaml/uml/node/method.rb +29 -0
  71. data/lib/lutaml/uml/node/method_argument.rb +16 -0
  72. data/lib/lutaml/uml/node/relationship.rb +28 -0
  73. data/lib/lutaml/uml/opaque_behavior.rb +11 -0
  74. data/lib/lutaml/uml/operation.rb +31 -0
  75. data/lib/lutaml/uml/package.rb +53 -0
  76. data/lib/lutaml/uml/parsers/attribute.rb +70 -0
  77. data/lib/lutaml/uml/parsers/dsl.rb +413 -0
  78. data/lib/lutaml/uml/parsers/dsl_preprocessor.rb +59 -0
  79. data/lib/lutaml/uml/parsers/dsl_transform.rb +27 -0
  80. data/lib/lutaml/uml/parsers/yaml.rb +46 -0
  81. data/lib/lutaml/uml/port.rb +8 -0
  82. data/lib/lutaml/uml/primitive_type.rb +14 -0
  83. data/lib/lutaml/uml/property.rb +27 -0
  84. data/lib/lutaml/uml/pseudostate.rb +11 -0
  85. data/lib/lutaml/uml/realization.rb +11 -0
  86. data/lib/lutaml/uml/region.rb +12 -0
  87. data/lib/lutaml/uml/serializers/association.rb +58 -0
  88. data/lib/lutaml/uml/serializers/base.rb +16 -0
  89. data/lib/lutaml/uml/serializers/class.rb +29 -0
  90. data/lib/lutaml/uml/serializers/top_element_attribute.rb +14 -0
  91. data/lib/lutaml/uml/serializers/yaml_view.rb +18 -0
  92. data/lib/lutaml/uml/state.rb +12 -0
  93. data/lib/lutaml/uml/state_machine.rb +12 -0
  94. data/lib/lutaml/uml/top_element.rb +58 -0
  95. data/lib/lutaml/uml/top_element_attribute.rb +39 -0
  96. data/lib/lutaml/uml/transition.rb +12 -0
  97. data/lib/lutaml/uml/trigger.rb +12 -0
  98. data/lib/lutaml/uml/value.rb +31 -0
  99. data/lib/lutaml/uml/version.rb +7 -0
  100. data/lib/lutaml/uml/vertex.rb +11 -0
  101. data/lib/lutaml/uml.rb +13 -0
  102. data/lib/lutaml/version.rb +1 -1
  103. data/lib/lutaml/xmi/README.adoc +24 -0
  104. data/lib/lutaml/xmi/parsers/xml.rb +600 -0
  105. data/lib/lutaml/xmi/version.rb +5 -0
  106. data/lib/lutaml/xmi.rb +7 -0
  107. data/lib/lutaml/xml/lutaml_path/document_wrapper.rb +45 -0
  108. data/lib/lutaml/xml/mapper.rb +448 -0
  109. data/lib/lutaml/xml/parsers/xml.rb +57 -0
  110. data/lib/lutaml/xml.rb +9 -0
  111. data/lutaml.gemspec +8 -3
  112. metadata +192 -16
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Lutaml
4
+ module Uml
5
+ module Formatter
6
+ class << self
7
+ def all
8
+ @all ||= []
9
+ end
10
+
11
+ def find_by_name(name)
12
+ name = name.to_sym
13
+
14
+ all.detect { |formatter_class| formatter_class.name == name }
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
20
+
21
+ require "lutaml/uml/formatter/graphviz"
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Lutaml
4
+ module Uml
5
+ module HasAttributes
6
+ def update_attributes(attributes = {})
7
+ attributes.to_h.each do |name, value|
8
+ value = value.respond_to?(:str) ? value.str : value
9
+ public_send("#{name}=", value)
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Lutaml
4
+ module Uml
5
+ module HasMembers
6
+ class UnknownMemberTypeError < StandardError; end
7
+
8
+ # TODO: move to Parslet::Transform
9
+ def members=(value)
10
+ value.group_by { |member| member.keys.first }
11
+ .each do |(type, group)|
12
+ attribute_value = group.map(&:values).flatten
13
+ if attribute_value.length == 1 && !attribute_value.first.is_a?(Hash)
14
+ next public_send("#{associtaion_type(type)}=", attribute_value.first)
15
+ end
16
+
17
+ public_send("#{associtaion_type(type)}=", attribute_value)
18
+ end
19
+ end
20
+
21
+ private
22
+
23
+ def associtaion_type(type)
24
+ return type if respond_to?("#{type}=")
25
+
26
+ raise(UnknownMemberTypeError, "Unknown member type: #{type}")
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Lutaml
4
+ module Uml
5
+ class Instance < TopElement
6
+ attr_accessor :classifier, :slot
7
+
8
+ def initialize
9
+ @name = nil
10
+ @xmi_id = nil
11
+ @xmi_uuid = nil
12
+ @classifier = nil
13
+ @slot = []
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Lutaml
4
+ module Uml
5
+ class Model < Package
6
+ attr_accessor :viewpoint
7
+
8
+ def initialize
9
+ @contents = []
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "lutaml/uml/has_attributes"
4
+
5
+ module Lutaml
6
+ module Uml
7
+ module Node
8
+ class Base
9
+ include HasAttributes
10
+
11
+ # rubocop:disable Rails/ActiveRecordAliases
12
+ def initialize(attributes = {})
13
+ update_attributes(attributes)
14
+ end
15
+ # rubocop:enable Rails/ActiveRecordAliases
16
+
17
+ attr_accessor :parent
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,57 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "lutaml/uml/node/base"
4
+ require "lutaml/uml/node/field"
5
+ require "lutaml/uml/node/method"
6
+ require "lutaml/uml/node/relationship"
7
+ require "lutaml/uml/node/class_relationship"
8
+ require "lutaml/uml/node/has_name"
9
+
10
+ module Lutaml
11
+ module Uml
12
+ module Node
13
+ class ClassNode < Base
14
+ include HasName
15
+
16
+ attr_reader :modifier
17
+
18
+ def modifier=(value)
19
+ @modifier = value.to_s # TODO: Validate?
20
+ end
21
+
22
+ attr_reader :members
23
+
24
+ def members=(value)
25
+ @members = value.to_a.map do |member|
26
+ type = member.to_a[0][0] # TODO: This is dumb
27
+ attributes = member.to_a[0][1]
28
+ attributes[:parent] = self
29
+
30
+ case type
31
+ when :field then Field.new(attributes)
32
+ when :method then Method.new(attributes)
33
+ when :relationship then Relationship.new(attributes)
34
+ when :class_relationship then ClassRelationship.new(attributes)
35
+ end
36
+ end
37
+ end
38
+
39
+ def fields
40
+ @members.select { |member| member.class == Field }
41
+ end
42
+
43
+ def methods
44
+ @members.select { |member| member.class == Method }
45
+ end
46
+
47
+ def relationships
48
+ @members.select { |member| member.class == Relationship }
49
+ end
50
+
51
+ def class_relationships
52
+ @members.select { |member| member.class == ClassRelationship }
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "lutaml/uml/node/relationship"
4
+ require "lutaml/uml/node/has_name"
5
+
6
+ module Lutaml
7
+ module Uml
8
+ module Node
9
+ class ClassRelationship < Relationship
10
+ include HasName
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "lutaml/uml/node/base"
4
+ require "lutaml/uml/node/class_node"
5
+
6
+ module Lutaml
7
+ module Uml
8
+ module Node
9
+ class Document < Base
10
+ attr_reader :classes
11
+
12
+ def classes=(value)
13
+ @classes = value.to_a.map { |attributes| ClassNode.new(attributes) }
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "lutaml/uml/node/base"
4
+ require "lutaml/uml/node/has_name"
5
+ require "lutaml/uml/node/has_type"
6
+
7
+ module Lutaml
8
+ module Uml
9
+ module Node
10
+ class Field < Base
11
+ include HasName
12
+ include HasType
13
+
14
+ def initialize(attributes = {})
15
+ @access = "public"
16
+
17
+ super
18
+ end
19
+
20
+ attr_reader :static
21
+
22
+ def static=(value)
23
+ @static = !!value
24
+ end
25
+
26
+ attr_reader :access
27
+
28
+ def access=(value)
29
+ @access = value.to_s # TODO: Validate?
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Lutaml
4
+ module Uml
5
+ module Node
6
+ module HasName
7
+ attr_reader :name
8
+
9
+ def name=(value)
10
+ @name = value.to_s
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Lutaml
4
+ module Uml
5
+ module Node
6
+ module HasType
7
+ attr_reader :type
8
+
9
+ def type=(value)
10
+ @type = value.to_s
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "lutaml/uml/node/field"
4
+ require "lutaml/uml/node/method_argument"
5
+ require "lutaml/uml/node/has_name"
6
+
7
+ module Lutaml
8
+ module Uml
9
+ module Node
10
+ class Method < Field
11
+ include HasName
12
+
13
+ attr_reader :abstract
14
+
15
+ def abstract=(value)
16
+ @abstract = !!value
17
+ end
18
+
19
+ attr_reader :arguments
20
+
21
+ def arguments=(value)
22
+ @arguments = value.to_a.map do |attributes|
23
+ MethodArgument.new(attributes)
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "lutaml/uml/node/base"
4
+ require "lutaml/uml/node/has_name"
5
+ require "lutaml/uml/node/has_type"
6
+
7
+ module Lutaml
8
+ module Uml
9
+ module Node
10
+ class MethodArgument < Base
11
+ include HasName
12
+ include HasType
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "lutaml/uml/node/base"
4
+ require "lutaml/uml/node/has_name"
5
+ require "lutaml/uml/node/has_type"
6
+
7
+ module Lutaml
8
+ module Uml
9
+ module Node
10
+ class Relationship < Base
11
+ include HasName
12
+ include HasType
13
+
14
+ attr_reader :from
15
+
16
+ def from=(value)
17
+ @from = value.to_s
18
+ end
19
+
20
+ attr_reader :to
21
+
22
+ def to=(value)
23
+ @to = value.to_s
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ ##
4
+ ## Behaviour metamodel
5
+ ##
6
+ module Lutaml
7
+ module Uml
8
+ class OpaqueBehavior < Behavior
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Lutaml
4
+ module Uml
5
+ class Operation
6
+ include HasAttributes
7
+ include HasMembers
8
+
9
+ attr_accessor :definition,
10
+ :name,
11
+ :return_type,
12
+ :parameter_type
13
+
14
+ # rubocop:disable Rails/ActiveRecordAliases
15
+ def initialize(attributes = {})
16
+ update_attributes(attributes)
17
+ end
18
+ # rubocop:enable Rails/ActiveRecordAliases
19
+
20
+ def definition=(value)
21
+ @definition = value
22
+ .to_s
23
+ .gsub(/\\}/, '}')
24
+ .gsub(/\\{/, '{')
25
+ .split("\n")
26
+ .map(&:strip)
27
+ .join("\n")
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,53 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Lutaml
4
+ module Uml
5
+ class Package < TopElement
6
+ include HasAttributes
7
+
8
+ attr_accessor :imports, :contents
9
+ attr_reader :classes, :enums, :data_types, :children_packages
10
+
11
+ def initialize(attributes)
12
+ update_attributes(attributes)
13
+ @children_packages ||= packages.map { |pkg| [pkg, pkg.packages, pkg.packages.map(&:children_packages)] }.flatten.uniq
14
+ end
15
+
16
+ def classes=(value)
17
+ @classes = value.to_a.map { |attributes| Class.new(attributes) }
18
+ end
19
+
20
+ def enums=(value)
21
+ @enums = value.to_a.map { |attributes| Enum.new(attributes) }
22
+ end
23
+
24
+ def data_types=(value)
25
+ @data_types = value.to_a.map { |attributes| DataType.new(attributes) }
26
+ end
27
+
28
+ def packages=(value)
29
+ @packages = value.to_a.map { |attributes| Package.new(attributes) }
30
+ end
31
+
32
+ def diagrams=(value)
33
+ @diagrams = value.to_a.map { |attributes| Diagram.new(attributes) }
34
+ end
35
+
36
+ def classes
37
+ @classes || []
38
+ end
39
+
40
+ def enums
41
+ @enums || []
42
+ end
43
+
44
+ def packages
45
+ @packages || []
46
+ end
47
+
48
+ def diagrams
49
+ @diagrams || []
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,70 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "parslet"
4
+
5
+ module Lutaml
6
+ module Uml
7
+ module Parsers
8
+ class Attribute < Parslet::Parser
9
+ class Transform < Parslet::Transform
10
+ rule(integer: simple(:x)) { Integer(x) }
11
+ rule(float: simple(:x)) { Float(x) }
12
+ rule(string: simple(:x)) { String(x) }
13
+ end
14
+
15
+ def self.parse(io, options = {})
16
+ new.parse(io, options)
17
+ end
18
+
19
+ def parse(io, options = {})
20
+ tree = Transform.new.apply(super)
21
+ tree = tree[:assignments].each_with_object({}) do |assignment, memo|
22
+ memo[assignment[:name].to_s] = assignment[:value]
23
+ end
24
+
25
+ tree
26
+ end
27
+
28
+ rule(:spaces) { match("\s").repeat(1) }
29
+ rule(:spaces?) { spaces.maybe }
30
+
31
+ rule(:digits) { match["0-9"].repeat(1) }
32
+
33
+ rule(:integer) do
34
+ (str("-").maybe >> digits >> str(".").absent?).as(:integer)
35
+ end
36
+ rule(:float) do
37
+ (str("-").maybe >> digits >> str(".") >> digits).as(:float)
38
+ end
39
+
40
+ rule(:string_single_quoted) do
41
+ str("'") >>
42
+ (str("'").absent? >> any).repeat.as(:string) >>
43
+ str("'")
44
+ end
45
+ rule(:string_double_quoted) do
46
+ str('"') >>
47
+ (str('"').absent? >> any).repeat.as(:string) >>
48
+ str('"')
49
+ end
50
+
51
+ rule(:string) { string_single_quoted | string_double_quoted }
52
+
53
+ rule(:assignment_name) do
54
+ (match["=\s"].absent? >> any).repeat.as(:name)
55
+ end
56
+ rule(:assignment_value) { (integer | float | string).as(:value) }
57
+ rule(:assignment) do
58
+ assignment_name >> spaces? >> str("=") >> spaces? >> assignment_value
59
+ end
60
+
61
+ rule(:attribute) { spaces? >> assignment >> spaces? }
62
+ rule(:attributes) do
63
+ (attribute >> (str(",") >> attribute).repeat).repeat.as(:assignments)
64
+ end
65
+
66
+ root(:attributes)
67
+ end
68
+ end
69
+ end
70
+ end