Class: Archimate::DataModel::Relationship

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

Overview

A base relationship type that can be extended by concrete ArchiMate types.

Note that RelationshipType is abstract, so one must have derived types of this type. this is indicated in xml by having a tag name of “relationship” and an attribute of xsi:type=“AccessRelationship” where AccessRelationship is a derived type from RelationshipType.

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, properties: [], source:, target:, access_type: nil) ⇒ Relationship

Returns a new instance of Relationship.



48
49
50
51
52
53
54
55
56
57
58
# File 'lib/archimate/data_model/relationship.rb', line 48

def initialize(id:, name: nil, documentation: nil, type: nil,
               properties: [], source:, target:, access_type: nil)
  @id = id
  @name = name
  @documentation = documentation
  @type = type
  @properties = properties
  @source = source
  @target = target
  @access_type = access_type
end

Instance Attribute Details

#access_typeAccessTypeEnum, NilClass (readonly)

Returns:



46
# File 'lib/archimate/data_model/relationship.rb', line 46

model_attr :access_type

#documentationPreservedLangString, NilClass (readonly)

Returns:



24
# File 'lib/archimate/data_model/relationship.rb', line 24

model_attr :documentation

#idString (readonly)

Returns:

  • (String)


18
# File 'lib/archimate/data_model/relationship.rb', line 18

model_attr :id

#nameLangString, NilClass (readonly)

Returns:



21
# File 'lib/archimate/data_model/relationship.rb', line 21

model_attr :name

#propertiesArray<Property> (readonly)

Returns:



35
# File 'lib/archimate/data_model/relationship.rb', line 35

model_attr :properties

#sourceElement, Relationship

Returns:



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

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

#targetElement, Relationship

Returns:



43
# File 'lib/archimate/data_model/relationship.rb', line 43

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

#typeString, NilClass (readonly)

Returns:

  • (String, NilClass)


32
# File 'lib/archimate/data_model/relationship.rb', line 32

model_attr :type

Instance Method Details

#descriptionObject



72
73
74
75
76
77
# File 'lib/archimate/data_model/relationship.rb', line 72

def description
  [
    name.nil? ? nil : "#{name}:",
    RELATION_VERBS.fetch(type, nil)
  ].compact.join(" ")
end

#diagramsObject

Diagrams that this element is referenced in.



86
87
88
89
90
# File 'lib/archimate/data_model/relationship.rb', line 86

def diagrams
  @diagrams ||= in_model.diagrams.select do |diagram|
    diagram.relationship_ids.include?(id)
  end
end

#merge(relationship) ⇒ Object

Copy any attributes/docs, etc. from each of the others into the original.

1. Child `label`s with different `xml:lang` attribute values
2. Child `documentation` (and different `xml:lang` attribute values)
3. Child `properties`
4. Any other elements

source and target don’t change on a merge



98
99
100
101
# File 'lib/archimate/data_model/relationship.rb', line 98

def merge(relationship)
  super
  access_type ||= relationship.access_type
end

#referenced_identified_nodesObject

Deprecated.
TODO:

remove when it doesn’t break diff merge conflicts



81
82
83
# File 'lib/archimate/data_model/relationship.rb', line 81

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

#replace(entity, with_entity) ⇒ Object



60
61
62
63
# File 'lib/archimate/data_model/relationship.rb', line 60

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

#to_sObject



65
66
67
68
69
70
# File 'lib/archimate/data_model/relationship.rb', line 65

def to_s
  Archimate::Color.color(
    "#{Archimate::Color.data_model(type)}<#{id}>[#{Archimate::Color.color(name&.strip || '', %i[black underline])}]",
    :on_light_magenta
  ) + " #{source} -> #{target}"
end