archimate 2.0.1 → 2.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (65) hide show
  1. checksums.yaml +4 -4
  2. data/archimate.gemspec +2 -1
  3. data/lib/archimate/color.rb +2 -2
  4. data/lib/archimate/data_model/any_attribute.rb +4 -10
  5. data/lib/archimate/data_model/any_element.rb +9 -17
  6. data/lib/archimate/data_model/bounds.rb +6 -6
  7. data/lib/archimate/data_model/color.rb +6 -6
  8. data/lib/archimate/data_model/comparison.rb +101 -5
  9. data/lib/archimate/data_model/concern.rb +5 -13
  10. data/lib/archimate/data_model/connection.rb +39 -48
  11. data/lib/archimate/data_model/connector_type.rb +1 -0
  12. data/lib/archimate/data_model/diagram.rb +27 -42
  13. data/lib/archimate/data_model/diagram_type.rb +1 -0
  14. data/lib/archimate/data_model/element.rb +14 -35
  15. data/lib/archimate/data_model/elements.rb +681 -0
  16. data/lib/archimate/data_model/font.rb +8 -8
  17. data/lib/archimate/data_model/lang_string.rb +10 -36
  18. data/lib/archimate/data_model/layer.rb +4 -5
  19. data/lib/archimate/data_model/layers.rb +45 -49
  20. data/lib/archimate/data_model/location.rb +6 -6
  21. data/lib/archimate/data_model/metadata.rb +2 -6
  22. data/lib/archimate/data_model/model.rb +50 -62
  23. data/lib/archimate/data_model/modeling_note.rb +3 -8
  24. data/lib/archimate/data_model/organization.rb +18 -27
  25. data/lib/archimate/data_model/property.rb +9 -8
  26. data/lib/archimate/data_model/property_definition.rb +15 -21
  27. data/lib/archimate/data_model/referenceable.rb +14 -9
  28. data/lib/archimate/data_model/referenceable_list.rb +82 -0
  29. data/lib/archimate/data_model/relationship.rb +41 -152
  30. data/lib/archimate/data_model/relationship_references.rb +29 -0
  31. data/lib/archimate/data_model/relationships.rb +214 -0
  32. data/lib/archimate/data_model/schema_info.rb +6 -12
  33. data/lib/archimate/data_model/style.rb +14 -25
  34. data/lib/archimate/data_model/view_node.rb +38 -66
  35. data/lib/archimate/data_model/viewpoint.rb +23 -38
  36. data/lib/archimate/data_model/viewpoint_type.rb +347 -387
  37. data/lib/archimate/data_model.rb +7 -6
  38. data/lib/archimate/derived_relations.rb +106 -31
  39. data/lib/archimate/export/cypher.rb +0 -18
  40. data/lib/archimate/export/jsonl.rb +16 -45
  41. data/lib/archimate/export/n_quads.rb +1 -24
  42. data/lib/archimate/file_formats/archi_file_reader.rb +2 -1
  43. data/lib/archimate/file_formats/model_exchange_file_writer_21.rb +9 -1
  44. data/lib/archimate/file_formats/sax/archi/archi_handler_factory.rb +2 -2
  45. data/lib/archimate/file_formats/sax/archi/connection.rb +2 -1
  46. data/lib/archimate/file_formats/sax/archi/element.rb +7 -5
  47. data/lib/archimate/file_formats/sax/archi/relationship.rb +1 -1
  48. data/lib/archimate/file_formats/sax/model_exchange_file/connection.rb +2 -1
  49. data/lib/archimate/file_formats/sax/model_exchange_file/element.rb +1 -1
  50. data/lib/archimate/file_formats/sax/model_exchange_file/relationship.rb +1 -1
  51. data/lib/archimate/file_formats/sax/model_exchange_file/view_node.rb +0 -1
  52. data/lib/archimate/file_formats/serializer/archi/relationship.rb +1 -1
  53. data/lib/archimate/lint/duplicate_entities.rb +46 -42
  54. data/lib/archimate/svg/archimate.css +12 -2
  55. data/lib/archimate/svg/entity/base_entity.rb +6 -29
  56. data/lib/archimate/svg/entity/location.rb +1 -0
  57. data/lib/archimate/svg/entity_factory.rb +3 -3
  58. data/lib/archimate/svg/point.rb +3 -3
  59. data/lib/archimate/svg/svg_template.svg.erb +5 -5
  60. data/lib/archimate/version.rb +2 -1
  61. metadata +20 -6
  62. data/TODOs.org +0 -505
  63. data/lib/archimate/data_model/differentiable.rb +0 -142
  64. data/lib/archimate/data_model/element_type.rb +0 -89
  65. data/lib/archimate/data_model/relationship_type.rb +0 -45
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 37d66a474e8d614dd2ccbbf746511e3c4b769ef7
4
- data.tar.gz: 50e1139f2d69beb50da6e702bd0e20d226f615fa
3
+ metadata.gz: 4adaa55a050dfda4d29150a63c15860a21f50932
4
+ data.tar.gz: 78c4c98ef53b79704018ef5b761377ac01e4497d
5
5
  SHA512:
6
- metadata.gz: e406c34a0b01b3f839f2ff8e9a688e7a5222ed02203bb0db45fdb03a71f6db5a9d8f9b9c575fa661ae3ce12ed8c7448cc340acea05c042097418eab8bffc498b
7
- data.tar.gz: 64c3e07d73f2b053c790fb37a3d8f32129f35da594a03fc4a7fe4b6cb66ed15e4e27d1ef83fcd4d5b0e66bd4ce56962aa82bc567717ddaef4878d52eac109d84
6
+ metadata.gz: ad77b807f9800be3bd0b4cde9a8dffa00161b94925aa2fdaf7519bfbcd80a71a63acc80ef294647b6d442cbb92b41113c50de10397bd7b9831a52acfb5d35a38
7
+ data.tar.gz: ef2e775c6067f3a9b097c853083d687af9289ce28f68d7d36a166257e2572af06089bab38513f4c7661cb0d30810bba271f89a4be82b0724beeafa46e225b66a
data/archimate.gemspec CHANGED
@@ -1,5 +1,5 @@
1
- # coding: utf-8
2
1
  # frozen_string_literal: true
2
+
3
3
  lib = File.expand_path('../lib', __FILE__)
4
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
5
  require 'archimate/version'
@@ -48,4 +48,5 @@ Gem::Specification.new do |spec|
48
48
  spec.add_development_dependency "faker"
49
49
  spec.add_development_dependency "rsense"
50
50
  spec.add_development_dependency "awesome_print"
51
+ spec.add_development_dependency "rubocop"
51
52
  end
@@ -23,7 +23,7 @@ HighLine.color_scheme = HighLine::ColorScheme.new do |cs|
23
23
  cs[:Connectors] = %i[black on_light_gray]
24
24
  cs[:unknown_layer] = %i[black on_gray]
25
25
  cs[:Model] = [:cyan]
26
- cs[:Connection] = [:blue]
26
+ cs[:Connection] = [:blue]
27
27
  cs[:Organization] = [:cyan]
28
28
  cs[:Relationship] = %i[black on_light_gray]
29
29
  cs[:Diagram] = %i[black on_cyan]
@@ -33,7 +33,7 @@ end
33
33
  module Archimate
34
34
  class Color
35
35
  def self.layer_color(layer, str)
36
- layer_sym = layer.to_sym
36
+ layer_sym = layer&.to_sym
37
37
  sym = HighLine.color_scheme.include?(layer_sym) ? layer_sym : :unknown_layer
38
38
  color(str, sym)
39
39
  end
@@ -7,20 +7,14 @@ module Archimate
7
7
  include Comparison
8
8
 
9
9
  # @!attribute [r] attribute
10
- # @return [String]
10
+ # @return [String]
11
11
  model_attr :attribute
12
12
  # @!attribute [r] prefix
13
- # @return [String]
14
- model_attr :prefix
13
+ # @return [String]
14
+ model_attr :prefix, default: ""
15
15
  # @!attribute [r] value
16
- # @return [String]
16
+ # @return [String]
17
17
  model_attr :value
18
-
19
- def initialize(attribute, value, prefix: "")
20
- @attribute = attribute
21
- @prefix = prefix
22
- @value = value
23
- end
24
18
  end
25
19
  end
26
20
  end
@@ -7,28 +7,20 @@ module Archimate
7
7
  include Comparison
8
8
 
9
9
  # @!attribute [r] element
10
- # @return [String]
10
+ # @return [String]
11
11
  model_attr :element
12
12
  # @!attribute [r] prefix
13
- # @return [String, NilClass]
14
- model_attr :prefix
13
+ # @return [String, NilClass]
14
+ model_attr :prefix, default: ""
15
15
  # @!attribute [r] attributes
16
- # @return [Array<AnyAttribute>]
17
- model_attr :attributes
16
+ # @return [Array<AnyAttribute>]
17
+ model_attr :attributes, default: []
18
18
  # @!attribute [r] content
19
- # @return [String, NilClass]
20
- model_attr :content
19
+ # @return [String, NilClass]
20
+ model_attr :content, default: nil
21
21
  # @!attribute [r] children
22
- # @return [Array<AnyElement>]
23
- model_attr :children
24
-
25
- def initialize(element:, prefix: "", attributes: [], content: nil, children: [])
26
- @element = element
27
- @prefix = prefix
28
- @attributes = attributes
29
- @content = content
30
- @children = children
31
- end
22
+ # @return [Array<AnyElement>]
23
+ model_attr :children, default: []
32
24
 
33
25
  def to_sym
34
26
  element&.to_sym
@@ -6,16 +6,16 @@ module Archimate
6
6
  include Comparison
7
7
 
8
8
  # @!attribute [r] x
9
- # @return [Float, NilClass]
10
- model_attr :x
9
+ # @return [Float, NilClass]
10
+ model_attr :x, default: nil
11
11
  # @!attribute [r] y
12
- # @return [Float, NilClass]
13
- model_attr :y
12
+ # @return [Float, NilClass]
13
+ model_attr :y, default: nil
14
14
  # @!attribute [r] width
15
- # @return [Float]
15
+ # @return [Float]
16
16
  model_attr :width
17
17
  # @!attribute [r] height
18
- # @return [Float]
18
+ # @return [Float]
19
19
  model_attr :height
20
20
 
21
21
  def self.zero
@@ -10,16 +10,16 @@ module Archimate
10
10
  include Comparison
11
11
 
12
12
  # @!attribute [r] r
13
- # @return [Int] red component, value 0-255
13
+ # @return [Int] red component, value 0-255
14
14
  model_attr :r
15
15
  # @!attribute [r] g
16
- # @return [Int] green component, value 0-255
16
+ # @return [Int] green component, value 0-255
17
17
  model_attr :g
18
18
  # @!attribute [r] b
19
- # @return [Int] blue component, value 0-255
19
+ # @return [Int] blue component, value 0-255
20
20
  model_attr :b
21
21
  # @!attribute [r] a
22
- # @return [Int, NilClass] optional alpha component, value 0-100
22
+ # @return [Int, NilClass] optional alpha component, value 0-100
23
23
  model_attr :a
24
24
 
25
25
  # Parses a CSS style color string into a color object
@@ -45,8 +45,8 @@ module Archimate
45
45
 
46
46
  def initialize(r:, g:, b:, a: nil)
47
47
  raise "r, g, b cannot be nil" if [r, g, b].any?(&:nil?)
48
- raise "r, g, b must be between 0 and 255" if [r, g, b].any? { |v| v < 0 || v > 255 }
49
- raise "a must be between 0 and 100" if a && (a < 0 || a > 100)
48
+ raise "r, g, b must be between 0 and 255" if [r, g, b].any? { |v| v.negative? || v > 255 }
49
+ raise "a must be between 0 and 100" if a && (a.negative? || a > 100)
50
50
  @r = r
51
51
  @g = g
52
52
  @b = b
@@ -3,6 +3,32 @@
3
3
  module Archimate
4
4
  module DataModel
5
5
  module Comparison
6
+ def initialize(opts = {})
7
+ self.class.attr_info.each do |sym, attr_info|
8
+ if attr_info.default == :value_required && !opts.include?(sym)
9
+ raise "#{self.class} required value for #{sym} is missing."
10
+ end
11
+ val = opts.fetch(sym, attr_info.default)
12
+ instance_variable_set("@#{sym}".to_sym, val)
13
+ val.add_reference(self) if val.is_a?(Referenceable)
14
+ end
15
+
16
+ self.class.attr_info.each do |sym, attr_info|
17
+ if attr_info.referenceable_list
18
+ instance_variable_set(
19
+ "@#{sym}".to_sym,
20
+ ReferenceableList.new(self, opts.fetch(sym, attr_info.default), attr_info.also_reference)
21
+ )
22
+ elsif attr_info.also_reference.size.positive?
23
+ val = instance_variable_get("@#{sym}".to_sym)
24
+ attr_info.also_reference.each do |ref_sym|
25
+ ref = send(ref_sym)
26
+ val.add_reference(ref) if ref && val
27
+ end
28
+ end
29
+ end
30
+ end
31
+
6
32
  def hash
7
33
  @hash_key ||=
8
34
  self.class.attr_names.reduce(self.class.hash) { |ha, attr| ha ^ send(attr).hash }
@@ -35,6 +61,8 @@ module Archimate
35
61
  self.class.comparison_attr_paths.each(&blk)
36
62
  end
37
63
 
64
+ # @todo implement pretty_print as a more normal pretty_print with correct
65
+ # handling for attr_info values for comparison_attr
38
66
  def pretty_print(pp)
39
67
  pp.object_address_group(self) do
40
68
  pp.seplist(self.class.comparison_attr_paths, proc { pp.text ',' }) do |attr|
@@ -50,26 +78,90 @@ module Archimate
50
78
  end
51
79
  end
52
80
 
81
+ # @todo implement inspect as a more normal inspect with correct handling for
82
+ # attr_info values for comparison_attr
83
+ def inspect
84
+ "#<#{self.class.to_s.split('::').last}\n " +
85
+ self.class.attr_info
86
+ .map { |sym, info| info.attr_inspect(self, sym) }
87
+ .compact
88
+ .join("\n ") + "\n >"
89
+ end
90
+
91
+ def brief_inspect
92
+ "#<#{self.class.to_s.split('::').last}#{" id=#{id}" if respond_to?(:id)}#{" #{name.brief_inspect}" if respond_to?(:name) && name}>"
93
+ end
94
+
53
95
  def self.included(base)
54
96
  base.extend ClassMethods
55
97
  end
56
98
 
57
99
  module ClassMethods
100
+ AttributeInfo = Struct.new(:comparison_attr, :writable, :default, :referenceable_list, :also_reference) do
101
+ def attr_inspect(obj, sym)
102
+ case comparison_attr
103
+ when :no_compare
104
+ nil
105
+ when nil
106
+ "#{sym}: #{attr_value_inspect(obj.send(sym))}"
107
+ else
108
+ val = obj.send(sym)
109
+ cval = val&.send(comparison_attr)
110
+ "#{sym}: #<#{val.class.to_s.split('::').last} #{comparison_attr}=#{attr_value_inspect(cval)}>"
111
+ end
112
+ end
113
+
114
+ def attr_value_inspect(val)
115
+ case val
116
+ when Comparison
117
+ val.brief_inspect
118
+ when Array
119
+ vals = val.first(3).map do |v|
120
+ if v.is_a?(Comparison)
121
+ v.brief_inspect
122
+ else
123
+ v.inspect
124
+ end
125
+ end
126
+ "[#{vals.join(', ')}#{"...#{val.size}" if val.size > 3}]"
127
+ else
128
+ val.inspect
129
+ end
130
+ end
131
+ end
132
+
58
133
  # Define the reader method (or call model_attr)
59
134
  # Append the attr_sym to the @@attrs for the class
60
- def model_attr(attr_sym, comparison_attr: nil, writable: false)
135
+ def model_attr(attr_sym, comparison_attr: nil, writable: false,
136
+ default: :value_required, referenceable_list: false,
137
+ also_reference: [])
61
138
  send(:attr_reader, attr_sym)
62
139
  attrs = attr_names << attr_sym
63
140
  class_variable_set(:@@attr_names, attrs.uniq)
64
-
141
+ class_variable_set(
142
+ :@@attr_info,
143
+ attr_info.merge(attr_sym => AttributeInfo.new(
144
+ comparison_attr, writable, default, referenceable_list, also_reference
145
+ ))
146
+ )
65
147
  if comparison_attr != :no_compare
66
148
  attrs = comparison_attr_paths << (comparison_attr ? [attr_sym, comparison_attr] : attr_sym)
67
149
  class_variable_set(:@@comparison_attr_paths, attrs.uniq)
68
150
  end
69
- if writable
70
- define_method("#{attr_sym}=".to_sym) do |val|
71
- instance_variable_set(:@hash_key, nil)
151
+ return unless writable
152
+ define_method("#{attr_sym}=".to_sym) do |val|
153
+ instance_variable_set(:@hash_key, nil)
154
+ old_val = instance_variable_get("@#{attr_sym}")
155
+ if old_val.is_a?(ReferenceableList)
156
+ old_val.replace_with(val)
157
+ else
158
+ old_val.remove_reference(self) if old_val.is_a?(Referenceable)
72
159
  instance_variable_set("@#{attr_sym}".to_sym, val)
160
+ val.add_reference(self) if val.is_a?(Referenceable)
161
+ also_reference.each do |ref_sym|
162
+ ref = send(ref_sym)
163
+ val.add_reference(ref) if ref && val
164
+ end
73
165
  end
74
166
  end
75
167
  end
@@ -78,6 +170,10 @@ module Archimate
78
170
  class_variable_defined?(:@@attr_names) ? class_variable_get(:@@attr_names) : []
79
171
  end
80
172
 
173
+ def attr_info
174
+ class_variable_defined?(:@@attr_info) ? class_variable_get(:@@attr_info) : {}
175
+ end
176
+
81
177
  def comparison_attr_paths
82
178
  class_variable_defined?(:@@comparison_attr_paths) ? class_variable_get(:@@comparison_attr_paths) : []
83
179
  end
@@ -9,22 +9,14 @@ module Archimate
9
9
  include Comparison
10
10
 
11
11
  # @!attribute [r] label
12
- # @return [LangString] one label is required
12
+ # @return [LangString] one label is required
13
13
  model_attr :label
14
14
  # @!attribute [r] documentation
15
- # @return [PreservedLangString]
16
- model_attr :documentation
15
+ # @return [PreservedLangString]
16
+ model_attr :documentation, default: nil
17
17
  # @!attribute [r] stakeholders
18
- # @return [Array<LangString>]
19
- model_attr :stakeholders
20
-
21
- def initialize(label:, documentation: nil, stakeholders: [])
22
- raise "label is required" unless label
23
- raise "stakeholders is a list" unless stakeholders.is_a?(Array)
24
- @label = label
25
- @documentation = documentation
26
- @stakeholders = stakeholders
27
- end
18
+ # @return [Array<LangString>]
19
+ model_attr :stakeholders, default: []
28
20
  end
29
21
  end
30
22
  end
@@ -4,75 +4,66 @@ module Archimate
4
4
  module DataModel
5
5
  # Graphical connection type.
6
6
  #
7
- # If the 'relationshipRef' attribute is present, the connection should reference an existing ArchiMate relationship.
7
+ # If the 'relationshipRef' attribute is present, the connection should
8
+ # reference an existing ArchiMate relationship.
8
9
  #
9
- # If the connection is an ArchiMate relationship type, the connection's label, documentation and properties may be determined
10
- # (i.e inherited) from those in the referenced ArchiMate relationship. Otherwise the connection's label, documentation and properties
11
- # can be provided and will be additional to (or over-ride) those contained in the referenced ArchiMate relationship.
10
+ # If the connection is an ArchiMate relationship type, the connection's
11
+ # label, documentation and properties may be determined (i.e inherited)
12
+ # from those in the referenced ArchiMate relationship. Otherwise the
13
+ # connection's label, documentation and properties can be provided and will
14
+ # be additional to (or over-ride) those contained in the referenced
15
+ # ArchiMate relationship.
12
16
  class Connection
13
17
  include Comparison
18
+ include Referenceable
14
19
 
15
20
  # @!attribute [r] id
16
- # @return [String]
21
+ # @return [String]
17
22
  model_attr :id
18
23
  # @!attribute [r] name
19
- # @return [LangString, NilClass]
20
- model_attr :name
24
+ # @return [LangString, NilClass]
25
+ model_attr :name, default: nil
21
26
  # @!attribute [r] documentation
22
- # @return [PreservedLangString, NilClass]
23
- model_attr :documentation
27
+ # @return [PreservedLangString, NilClass]
28
+ model_attr :documentation, default: nil
24
29
  # # @!attribute [r] other_elements
25
- # @return [Array<AnyElement>]
26
- model_attr :other_elements
30
+ # @return [Array<AnyElement>]
31
+ model_attr :other_elements, default: []
27
32
  # # @!attribute [r] other_attributes
28
- # @return [Array<AnyAttribute>]
29
- model_attr :other_attributes
33
+ # @return [Array<AnyAttribute>]
34
+ model_attr :other_attributes, default: []
30
35
  # @note type here was used for the Element/Relationship/Diagram type
31
36
  # @!attribute [r] type
32
- # @return [String, NilClass]
33
- model_attr :type
37
+ # @return [String, NilClass]
38
+ model_attr :type, default: nil
34
39
  # @!attribute [r] source_attachment
35
- # @return [Location, NilClass]
36
- model_attr :source_attachment
40
+ # @return [Location, NilClass]
41
+ model_attr :source_attachment, default: nil
37
42
  # @!attribute [r] bendpoints
38
- # @return [Array<Location>]
39
- model_attr :bendpoints
43
+ # @return [Array<Location>]
44
+ model_attr :bendpoints, default: []
40
45
  # @!attribute [r] target_attachment
41
- # @return [Location, NilClass]
42
- model_attr :target_attachment
46
+ # @return [Location, NilClass]
47
+ model_attr :target_attachment, default: nil
43
48
  # @!attribute [rw] source
44
- # @return [ViewNode, NilClass]
45
- model_attr :source, comparison_attr: :id, writable: true
49
+ # @return [ViewNode, NilClass]
50
+ model_attr :source, comparison_attr: :id, writable: true, default: nil
46
51
  # @!attribute [rw] target
47
- # @return [ViewNode, NilClass]
48
- model_attr :target, comparison_attr: :id, writable: true
52
+ # @return [ViewNode, NilClass]
53
+ model_attr :target, comparison_attr: :id, writable: true, default: nil
49
54
  # @!attribute [rw] relationship
50
- # @return [Relationship, NilClass]
51
- model_attr :relationship, comparison_attr: :id, writable: true
55
+ # @return [Relationship, NilClass]
56
+ model_attr :relationship, comparison_attr: :id, writable: true, default: nil, also_reference: [:diagram]
52
57
  # @!attribute [r] style
53
- # @return [Style, NilClass]
54
- model_attr :style
58
+ # @return [Style, NilClass]
59
+ model_attr :style, default: nil
55
60
  # @!attribute [r] properties
56
- # @return [Array<Property>]
57
- model_attr :properties
61
+ # @return [Array<Property>]
62
+ model_attr :properties, default: []
58
63
 
59
- def initialize(id:, name: nil, documentation: nil, type: nil,
60
- source_attachment: nil, bendpoints: [], target_attachment: nil,
61
- source: nil, target: nil, relationship: nil, style: nil,
62
- properties: nil)
63
- @id = id
64
- @name = name
65
- @documentation = documentation
66
- @type = type
67
- @source_attachment = source_attachment
68
- @bendpoints = bendpoints
69
- @target_attachment = target_attachment
70
- @source = source
71
- @target = target
72
- @relationship = relationship
73
- @style = style
74
- @properties = properties
75
- end
64
+ # @!attribute [r] diagram
65
+ # @return [Diagram, NilClass]
66
+ model_attr :diagram, comparison_attr: :no_compare
76
67
 
77
68
  def replace(entity, with_entity)
78
69
  @relationship = with_entity.id if relationship == entity.id
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require "ruby-enum"
3
4
 
4
5
  module Archimate
@@ -4,64 +4,49 @@ module Archimate
4
4
  module DataModel
5
5
  class Diagram
6
6
  include Comparison
7
+ include Referenceable
7
8
 
8
9
  # @!attribute [r] id
9
- # @return [String]
10
+ # @return [String]
10
11
  model_attr :id
11
12
  # @!attribute [rw] name
12
- # @return [LangString]
13
- model_attr :name, writable: true
13
+ # @return [LangString]
14
+ model_attr :name, writable: true, default: nil
14
15
  # @!attribute [rw] documentation
15
- # @return [PreservedLangString, NilClass]
16
- model_attr :documentation, writable: true
17
- # # @return [Array<AnyElement>]
18
- # model_attr :other_elements
19
- # # @return [Array<AnyAttribute>]
20
- # model_attr :other_attributes
16
+ # @return [PreservedLangString, NilClass]
17
+ model_attr :documentation, writable: true, default: nil
18
+ # @return [Array<AnyElement>]
19
+ model_attr :other_elements, default: []
20
+ # @return [Array<AnyAttribute>]
21
+ model_attr :other_attributes, default: []
21
22
  # @note type here was used for the Element/Relationship/Diagram type
22
23
  # @!attribute [r] type
23
- # @return [String, NilClass]
24
- model_attr :type
24
+ # @return [String, NilClass]
25
+ model_attr :type, default: nil
25
26
  # @!attribute [rw] properties
26
- # @return [Array<Property>]
27
- model_attr :properties, writable: true
27
+ # @return [Array<Property>]
28
+ model_attr :properties, writable: true, default: []
28
29
  # @todo make this a ViewpointType is better but is Archimate specification version dependent
29
30
  # @!attribute [r] viewpoint_type
30
- # @return [String, NilClass]
31
- model_attr :viewpoint_type
31
+ # @return [String, NilClass]
32
+ model_attr :viewpoint_type, default: nil
32
33
  # @!attribute [r] viewpoint
33
- # @return [Viewpoint, NilClass]
34
- model_attr :viewpoint
34
+ # @return [Viewpoint, NilClass]
35
+ model_attr :viewpoint, default: nil
35
36
  # @!attribute [rw] nodes
36
- # @return [Array<ViewNode>]
37
- model_attr :nodes, writable: true
37
+ # @return [Array<ViewNode>]
38
+ model_attr :nodes, writable: true, default: [], referenceable_list: true
38
39
  # @todo Archi formats only fill this in, should be an enum
39
40
  # @!attribute [r] connection_router_type
40
- # @return [Int, NilClass]
41
- model_attr :connection_router_type
41
+ # @return [Int, NilClass]
42
+ model_attr :connection_router_type, default: nil
42
43
  # value of 0 on Archi Sketch Model
43
44
  # @!attribute [r] background
44
- # @return [Int, NilClass]
45
- model_attr :background
45
+ # @return [Int, NilClass]
46
+ model_attr :background, default: nil
46
47
  # @!attribute [rw] connections
47
- # @return [Array<Connection>]
48
- model_attr :connections, writable: true
49
-
50
- def initialize(id:, name: nil, documentation: nil, type: nil, properties: [],
51
- viewpoint_type: nil, viewpoint: nil, nodes: [],
52
- connection_router_type: nil, background: nil, connections: [])
53
- @id = id
54
- @name = name
55
- @documentation = documentation
56
- @type = type
57
- @properties = properties
58
- @viewpoint_type = viewpoint_type
59
- @viewpoint = viewpoint
60
- @nodes = nodes
61
- @connection_router_type = connection_router_type
62
- @background = background
63
- @connections = connections
64
- end
48
+ # @return [Array<Connection>]
49
+ model_attr :connections, writable: true, default: [], referenceable_list: true
65
50
 
66
51
  def all_nodes
67
52
  nodes.inject(Array.new(nodes)) { |child_ary, child| child_ary.concat(child.all_nodes) }
@@ -92,7 +77,7 @@ module Archimate
92
77
  end
93
78
 
94
79
  def referenced_identified_nodes
95
- (nodes + connections)
80
+ (nodes.to_ary + connections)
96
81
  .map(&:referenced_identified_nodes)
97
82
  .flatten
98
83
  .uniq
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require "ruby-enum"
3
4
 
4
5
  module Archimate
@@ -8,63 +8,42 @@ module Archimate
8
8
  # type. This is indicated in xml by having a tag name of +element+ and an
9
9
  # attribute of +xsi:type="BusinessRole"+ where +BusinessRole+ is a derived
10
10
  # type from [ElementType].
11
- #
12
- # @todo Possible Make this abstract with concrete implementations for all
13
- # valid element types
14
11
  class Element
15
12
  include Comparison
13
+ include Referenceable
14
+ include RelationshipReferences
16
15
 
17
16
  # @!attribute [r] id
18
- # @return [String]
17
+ # @return [String]
19
18
  model_attr :id
20
19
  # @!attribute [r] name
21
- # @return [LangString, NilClass]
20
+ # @return [LangString, NilClass]
22
21
  model_attr :name
23
22
  # @!attribute [rw] documentation
24
- # @return [PreservedLangString, NilClass]
25
- model_attr :documentation, writable: true
23
+ # @return [PreservedLangString, NilClass]
24
+ model_attr :documentation, writable: true, default: nil
26
25
  # # @return [Array<AnyElement>]
27
26
  # model_attr :other_elements
28
27
  # # @return [Array<AnyAttribute>]
29
28
  # model_attr :other_attributes
30
- # @note type here was used for the Element/Relationship/Diagram type
31
- # @!attribute [r] type
32
- # @return [String, NilClass]
33
- model_attr :type
34
29
  # @!attribute [r] properties
35
- # @return [Array<Property>]
36
- model_attr :properties
37
-
38
- def initialize(id:, name:, documentation: nil, type: nil, properties: [])
39
- @id = id
40
- @name = name
41
- @documentation = documentation
42
- @type = type
43
- @properties = properties
44
- end
30
+ # @return [Array<Property>]
31
+ model_attr :properties, default: []
45
32
 
46
33
  def to_s
47
34
  Archimate::Color.layer_color(layer, "#{type}<#{id}>[#{name}]")
48
35
  end
49
36
 
50
- def layer
51
- Layers.for_element(type)
37
+ def type
38
+ self.class.name.split("::").last
52
39
  end
53
40
 
54
- # Diagrams that this element is referenced in.
55
- # @todo this implementation is broken - in_model no longer exists
56
- def diagrams
57
- @diagrams ||= in_model.diagrams.select do |diagram|
58
- diagram.element_ids.include?(id)
59
- end
41
+ def classification
42
+ self.class::CLASSIFICATION
60
43
  end
61
44
 
62
- # Relationships that this element is referenced in.
63
- # @todo this implementation is broken - in_model no longer exists
64
- def relationships
65
- @relationships ||= in_model.relationships.select do |relationship|
66
- relationship.source == id || relationship.target == id
67
- end
45
+ def layer
46
+ self.class::LAYER
68
47
  end
69
48
 
70
49
  # Copy any attributes/docs, etc. from each of the others into the original.