Class: Archimate::DataModel::Relationship

Inherits:
Object
  • Object
show all
Includes:
Comparison, Referenceable
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 Referenceable

#add_reference, #destroy, #model, #references, #remove_reference, #replace_with

Methods included from Comparison

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

Instance Attribute Details

#access_typeAccessTypeEnum, NilClass (readonly)

Returns:



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

model_attr :access_type, default: nil

#derivedBoolean (readonly)

Returns this is a derived relation if true.

Returns:

  • (Boolean)

    this is a derived relation if true



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

model_attr :derived, default: false

#documentationPreservedLangString, NilClass (readonly)

Returns:



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

model_attr :documentation, writable: true, default: nil

#idString (readonly)

Returns:

  • (String)


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

model_attr :id

#nameLangString, NilClass (readonly)

Returns:



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

model_attr :name, default: nil

#propertiesArray<AnyElement>, ... (readonly)

model_attr :other_elements model_attr :other_attributes

Returns:



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

model_attr :properties, default: []

#sourceElement, Relationship

TODO:

is this optional?

Returns:



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

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

#targetElement, Relationship

TODO:

is this optional?

Returns:



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

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

Instance Method Details

#classificationObject



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

def classification
  self.class::CLASSIFICATION
end

#descriptionObject



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

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

#diagramsObject

Diagrams that this entity is referenced in.



105
106
107
# File 'lib/archimate/data_model/relationship.rb', line 105

def diagrams
  references.select { |ref| ref.is_a?(Diagram) }
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



90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/archimate/data_model/relationship.rb', line 90

def merge(relationship)
  if !documentation
    self.documentation = relationship.documentation
  elsif documentation != relationship.documentation
    documentation.merge(relationship.documentation)
  end
  relationship.properties.each do |property|
    unless properties.find { |my_prop| my_prop.property_definition.name == property.property_definition.name && my_prop.value == property.value}
      properties << property
    end
  end
  @access_type ||= relationship.access_type
end

#replace(entity, with_entity) ⇒ Object



49
50
51
52
# File 'lib/archimate/data_model/relationship.rb', line 49

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

#replace_item_with(item, replacement) ⇒ Object



109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/archimate/data_model/relationship.rb', line 109

def replace_item_with(item, replacement)
  super
  item.remove_reference(self)
  case item
  when source
    @source = replacement
  when target
    @target = replacement
  else
    raise "Trying to replace #{item} that I don't reference"
  end
end

#to_sObject



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

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

#typeObject



54
55
56
# File 'lib/archimate/data_model/relationship.rb', line 54

def type
  self.class.name.split("::").last
end

#verbObject



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

def verb
  self.class::VERB
end

#weightObject



58
59
60
# File 'lib/archimate/data_model/relationship.rb', line 58

def weight
  self.class::WEIGHT
end