Class: Archimate::DataModel::Model

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

Overview

This is the root model type.

It is a container for the elements, relationships, diagrams and organizations of the model.

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:, documentation: nil, properties: [], metadata: nil, elements: [], relationships: [], organizations: [], property_definitions: [], version: nil, diagrams: [], viewpoints: [], filename: nil, file_format: nil, archimate_version: :archimate_3_0, namespaces: {}, schema_locations: []) ⇒ Model

Constructor



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/archimate/data_model/model.rb', line 75

def initialize(id:, name:, documentation: nil, properties: [],
               metadata: nil, elements: [], relationships: [],
               organizations: [], property_definitions: [],
               version: nil, diagrams: [], viewpoints: [],
               filename: nil, file_format: nil, archimate_version: :archimate_3_0,
               namespaces: {}, schema_locations: [])
  @id = id
  @name = name
  @documentation = documentation
  @properties = properties
  @metadata = 
  @elements = elements
  @relationships = relationships
  @organizations = organizations
  @property_definitions = property_definitions
  @version = version
  @diagrams = diagrams
  @viewpoints = viewpoints
  @filename = filename
  @file_format = file_format
  @archimate_version = archimate_version
  @namespaces = namespaces
  @schema_locations = schema_locations
  rebuild_index
end

Instance Attribute Details

#archimate_versionSymbol (readonly)

Returns one of [Archimate::ARCHIMATE_VERSIONS], default :archimate_3_0.

Returns:

  • (Symbol)

    one of [Archimate::ARCHIMATE_VERSIONS], default :archimate_3_0



60
# File 'lib/archimate/data_model/model.rb', line 60

model_attr :archimate_version

#diagramsArray<Diagram> (readonly)

Returns:



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

model_attr :diagrams

#documentationPreservedLangString, NilClass (readonly)

Returns model documentation.

Returns:



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

model_attr :documentation

#elementsArray<Element> (readonly)

Returns:



30
# File 'lib/archimate/data_model/model.rb', line 30

model_attr :elements

#file_formatSymbol, NilClass (readonly)

Returns supported Archimate format [Archimate::SUPPORTED_FORMATS] or nil.

Returns:

  • (Symbol, NilClass)

    supported Archimate format [Archimate::SUPPORTED_FORMATS] or nil



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

model_attr :file_format

#filenameString (readonly)

Returns:

  • (String)


53
# File 'lib/archimate/data_model/model.rb', line 53

model_attr :filename

#idString (readonly)

Returns unique identifier of this model.

Returns:

  • (String)

    unique identifier of this model



14
# File 'lib/archimate/data_model/model.rb', line 14

model_attr :id

#metadataMetadata, NilClass (readonly)

Returns model metadata.

Returns:

  • (Metadata, NilClass)

    model metadata



27
# File 'lib/archimate/data_model/model.rb', line 27

model_attr :metadata

#nameLangString (readonly)

Returns name of the model.

Returns:



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

model_attr :name

#namespacesHash (readonly)

Returns:

  • (Hash)


64
# File 'lib/archimate/data_model/model.rb', line 64

model_attr :namespaces

#organizationsArray<Organization> (readonly)

Returns:



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

model_attr :organizations

#propertiesArray<Property> (readonly)

Returns model properties.

Returns:

  • (Array<Property>)

    model properties



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

model_attr :properties

#property_definitionsArray<PropertyDefinition> (readonly)

Returns:



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

model_attr :property_definitions

#relationshipsArray<Relationship> (readonly)

Returns:



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

model_attr :relationships

#schema_locationsArray<String> (readonly)

Returns:

  • (Array<String>)


67
# File 'lib/archimate/data_model/model.rb', line 67

model_attr :schema_locations

#versionString, NilClass (readonly)

Returns:

  • (String, NilClass)


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

model_attr :version

#viewpointsArray<Viewpoint> (readonly)

Returns:



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

model_attr :viewpoints

Instance Method Details

#entitiesObject

Called only by [Lint::DuplicateEntities]



107
108
109
# File 'lib/archimate/data_model/model.rb', line 107

def entities
  @index_hash.values
end

#lookup(id) ⇒ Object



101
102
103
104
# File 'lib/archimate/data_model/model.rb', line 101

def lookup(id)
  rebuild_index(id) unless @index_hash.include?(id)
  @index_hash[id]
end

#organizeObject

Note:

this is only called by [Diff::Merge]

Iterate through the model and ensure that elements, relationships, and diagrams are all present in the model’s organizations. If an item is missing then move it into the default top-level element for the item type.



127
128
129
130
131
132
133
134
135
136
137
138
# File 'lib/archimate/data_model/model.rb', line 127

def organize
  []
    .concat(elements)
    .concat(relationships)
    .concat(diagrams).each do |item|
      if find_in_organizations(item).nil?
        default_organization = default_organization_for(item)
        default_organization.items.push(item.id) unless default_organization.items.include?(item.id)
      end
    end
  self
end

#rebuild_index(missing_id = :model_creation_event) ⇒ Object

Called only by [Diff::Merge]



112
113
114
115
116
# File 'lib/archimate/data_model/model.rb', line 112

def rebuild_index(missing_id = :model_creation_event)
  return self unless missing_id
  @index_hash = build_index
  self
end

#referenced_identified_nodesObject

Only used by [Diff::DeletedItemsReferencedConflict]



141
142
143
144
145
146
147
148
149
# File 'lib/archimate/data_model/model.rb', line 141

def referenced_identified_nodes
  classes = [Diagram, ViewNode, Connection, Organization, Relationship].freeze
  @index_hash
    .values
    .select { |entity| classes.include?(entity.class) }
    .map(&:referenced_identified_nodes)
    .flatten
    .uniq
end

#to_sObject



118
119
120
# File 'lib/archimate/data_model/model.rb', line 118

def to_s
  "#{Archimate::Color.data_model('Model')}<#{id}>[#{Archimate::Color.color(name, %i[white underline])}]"
end

#unreferenced_nodesObject

This is used only by the model [Cli::Cleanup] class.



152
153
154
# File 'lib/archimate/data_model/model.rb', line 152

def unreferenced_nodes
  identified_nodes - referenced_identified_nodes
end