Class: Archimate::DataModel::Element

Inherits:
Concept show all
Defined in:
lib/archimate/data_model/element.rb

Overview

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

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

Instance Attribute Summary

Attributes inherited from ArchimateNode

#parent_attribute_name, #struct_instance_variables

Instance Method Summary collapse

Methods inherited from ArchimateNode

#ancestors, #build_index, #clone, #compact!, #delete, #diff, #dup, #element_by_id, #id, #in_model, #in_model=, #initialize, #parent, #parent=, #path, #primitive?, #referenced_identified_nodes, #set, #with

Constructor Details

This class inherits a constructor from Archimate::DataModel::ArchimateNode

Instance Method Details

#composed_byObject

TODO: move to dynamic method creation



45
46
47
48
49
# File 'lib/archimate/data_model/element.rb', line 45

def composed_by
  in_model
    .relationships.select { |r| r.type == "CompositionRelationship" && r.target == id }
    .map { |r| in_model.lookup(r.source) }
end

#composesObject

TODO: move to dynamic method creation



52
53
54
55
56
57
# File 'lib/archimate/data_model/element.rb', line 52

def composes
  in_model
    .relationships
    .select { |r| r.type == "CompositionRelationship" && r.source == id }
    .map { |r| in_model.lookup(r.target) }
end

#diagramsObject

Diagrams that this element is referenced in.



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

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

#layerObject



40
41
42
# File 'lib/archimate/data_model/element.rb', line 40

def layer
  Constants::ELEMENT_LAYER.fetch(type, "None")
end

#merge(element) ⇒ 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


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

def merge(element)
  super
  element.diagrams.each { |diagram| diagram.replace(element, self) }
  element.relationships.each { |relationship| relationship.replace(element, self) }
  element.organization.remove(element.id)
end

#relationshipsObject

Relationships that this element is referenced in.



67
68
69
70
71
# File 'lib/archimate/data_model/element.rb', line 67

def relationships
  @relationships ||= in_model.relationships.select do |relationship|
    relationship.source == id || relationship.target == id
  end
end

#to_sObject



36
37
38
# File 'lib/archimate/data_model/element.rb', line 36

def to_s
  Archimate::Color.layer_color(layer, "#{type}<#{id}>[#{name}]")
end