Class: Archimate::DataModel::Connection

Inherits:
Object
  • Object
show all
Includes:
Comparison
Defined in:
lib/archimate/data_model/connection.rb

Overview

Graphical connection type.

If the ‘relationshipRef’ attribute is present, the connection should reference an existing ArchiMate relationship.

If the connection is an ArchiMate relationship type, the connection’s label, documentation and properties may be determined (i.e inherited) from those in the referenced ArchiMate relationship. Otherwise the connection’s label, documentation and properties can be provided and will be additional to (or over-ride) those contained in the referenced ArchiMate relationship.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Comparison

#==, #[], #dig, #each, #hash, included, #pretty_print, #to_h

Constructor Details

#initialize(id:, name: nil, documentation: nil, type: nil, source_attachment: nil, bendpoints: [], target_attachment: nil, source: nil, target: nil, relationship: nil, style: nil, properties: nil) ⇒ Connection

Returns a new instance of Connection.



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/archimate/data_model/connection.rb', line 59

def initialize(id:, name: nil, documentation: nil, type: nil,
               source_attachment: nil, bendpoints: [], target_attachment: nil,
               source: nil, target: nil, relationship: nil, style: nil,
               properties: nil)
  @id = id
  @name = name
  @documentation = documentation
  @type = type
  @source_attachment = source_attachment
  @bendpoints = bendpoints
  @target_attachment = target_attachment
  @source = source
  @target = target
  @relationship = relationship
  @style = style
  @properties = properties
end

Instance Attribute Details

#bendpointsArray<Location> (readonly)

Returns:



39
# File 'lib/archimate/data_model/connection.rb', line 39

model_attr :bendpoints

#documentationPreservedLangString, NilClass (readonly)

Returns:



23
# File 'lib/archimate/data_model/connection.rb', line 23

model_attr :documentation

#idString (readonly)

Returns:

  • (String)


17
# File 'lib/archimate/data_model/connection.rb', line 17

model_attr :id

#nameLangString, NilClass (readonly)

Returns:



20
# File 'lib/archimate/data_model/connection.rb', line 20

model_attr :name

#propertiesArray<Property> (readonly)

Returns:



57
# File 'lib/archimate/data_model/connection.rb', line 57

model_attr :properties

#relationshipRelationship, NilClass

Returns:



51
# File 'lib/archimate/data_model/connection.rb', line 51

model_attr :relationship, comparison_attr: :id, writable: true

#sourceViewNode, NilClass

Returns:



45
# File 'lib/archimate/data_model/connection.rb', line 45

model_attr :source, comparison_attr: :id, writable: true

#source_attachmentLocation, NilClass (readonly)

Returns:



36
# File 'lib/archimate/data_model/connection.rb', line 36

model_attr :source_attachment

#styleStyle, NilClass (readonly)

Returns:



54
# File 'lib/archimate/data_model/connection.rb', line 54

model_attr :style

#targetViewNode, NilClass

Returns:



48
# File 'lib/archimate/data_model/connection.rb', line 48

model_attr :target, comparison_attr: :id, writable: true

#target_attachmentLocation, NilClass (readonly)

Returns:



42
# File 'lib/archimate/data_model/connection.rb', line 42

model_attr :target_attachment

#typeString, NilClass (readonly)

Returns:

  • (String, NilClass)


33
# File 'lib/archimate/data_model/connection.rb', line 33

model_attr :type

Instance Method Details

#absolute_positionObject

TODO: Is this true for all or only Archi models?



114
115
116
117
118
119
120
121
122
123
124
# File 'lib/archimate/data_model/connection.rb', line 114

def absolute_position
  # offset = bounds || Archimate::DataModel::Bounds.zero
  offset = Archimate::DataModel::Bounds.zero
  el = parent.parent
  while el.respond_to?(:bounds) && el.bounds
    bounds = el.bounds
    offset = offset.with(x: (offset.x || 0) + (bounds.x || 0), y: (offset.y || 0) + (bounds.y || 0))
    el = el.parent.parent
  end
  offset
end

#descriptionObject



95
96
97
98
99
100
101
102
# File 'lib/archimate/data_model/connection.rb', line 95

def description
  [
    name.nil? ? nil : "#{name}: ",
    source&.description,
    relationship&.description,
    target&.description
  ].compact.join(" ")
end

#elementObject



87
88
89
# File 'lib/archimate/data_model/connection.rb', line 87

def element
  relationship
end

#nodesObject

This is used when rendering a connection to connection relationship.



109
110
111
# File 'lib/archimate/data_model/connection.rb', line 109

def nodes
  []
end

#referenced_identified_nodesObject



104
105
106
# File 'lib/archimate/data_model/connection.rb', line 104

def referenced_identified_nodes
  [@source, @target, @relationship].compact
end

#replace(entity, with_entity) ⇒ Object



77
78
79
80
81
# File 'lib/archimate/data_model/connection.rb', line 77

def replace(entity, with_entity)
  @relationship = with_entity.id if relationship == entity.id
  @source = with_entity.id if source == entity.id
  @target = with_entity.id if target == entity.id
end

#to_sObject



91
92
93
# File 'lib/archimate/data_model/connection.rb', line 91

def to_s
  "#{type_name} #{source.nil? ? 'nothing' : source} -> #{target.nil? ? 'nothing' : target}"
end

#type_nameObject



83
84
85
# File 'lib/archimate/data_model/connection.rb', line 83

def type_name
  Archimate::Color.color("#{Archimate::Color.data_model('Connection')}[#{Archimate::Color.color(@name || '', %i[white underline])}]", :on_light_magenta)
end