Class: Archimate::DataModel::Model
- Inherits:
-
Object
- Object
- Archimate::DataModel::Model
- 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
-
#archimate_version ⇒ Symbol
readonly
One of [Archimate::ARCHIMATE_VERSIONS], default
:archimate_3_0
. - #diagrams ⇒ Array<Diagram> readonly
-
#documentation ⇒ PreservedLangString, NilClass
readonly
Model documentation.
- #elements ⇒ Array<Element> readonly
-
#file_format ⇒ Symbol, NilClass
readonly
Supported Archimate format [Archimate::SUPPORTED_FORMATS] or
nil
. -
#filename ⇒ String
readonly
Following attributes are to hold info on where the model came from.
-
#id ⇒ String
readonly
Unique identifier of this model.
-
#metadata ⇒ Metadata, NilClass
readonly
Model metadata.
-
#name ⇒ LangString
readonly
Name of the model.
- #namespaces ⇒ Hash readonly
- #organizations ⇒ Array<Organization> readonly
-
#properties ⇒ Array<Property>
readonly
Model properties.
- #property_definitions ⇒ Array<PropertyDefinition> readonly
- #relationships ⇒ Array<Relationship> readonly
- #schema_locations ⇒ Array<String> readonly
- #version ⇒ String, NilClass readonly
- #viewpoints ⇒ Array<Viewpoint> readonly
Instance Method Summary collapse
-
#entities ⇒ Object
Called only by [Lint::DuplicateEntities].
- #find_by_class(klass) ⇒ Object
-
#initialize(opts = {}) ⇒ Model
constructor
Constructor.
- #lookup(id) ⇒ Object
- #make_unique_id ⇒ Object
-
#merge_entities(master_entity, copies) ⇒ Object
Steps to merge merge attributes of each copy into master_entity update references of each copy to reference master_entity instead (where it makes sense) remove reference of each copy from its references.
-
#organize ⇒ Object
Iterate through the model and ensure that elements, relationships, and diagrams are all present in the model’s organizations.
- #other_attributes ⇒ Array<AnyAttribute>
- #other_elements ⇒ Array<AnyElement>
-
#rebuild_index(missing_id = :model_creation_event) ⇒ Object
Called only by [Diff::Merge].
- #remove_reference(item) ⇒ Object
- #replace_item_with(item, replacement) ⇒ Object
- #to_s ⇒ Object
Methods included from Comparison
#==, #[], #dig, #each, #hash, included, #inspect, #pretty_print, #to_h
Constructor Details
#initialize(opts = {}) ⇒ Model
Constructor
77 78 79 80 |
# File 'lib/archimate/data_model/model.rb', line 77 def initialize(opts = {}) super rebuild_index end |
Instance Attribute Details
#archimate_version ⇒ Symbol (readonly)
Returns one of [Archimate::ARCHIMATE_VERSIONS], default :archimate_3_0
.
62 |
# File 'lib/archimate/data_model/model.rb', line 62 model_attr :archimate_version, default: :archimate_3_0 |
#diagrams ⇒ Array<Diagram> (readonly)
47 |
# File 'lib/archimate/data_model/model.rb', line 47 model_attr :diagrams, default: [], referenceable_list: true |
#documentation ⇒ PreservedLangString, NilClass (readonly)
Returns model documentation.
23 |
# File 'lib/archimate/data_model/model.rb', line 23 model_attr :documentation, default: nil |
#elements ⇒ Array<Element> (readonly)
32 |
# File 'lib/archimate/data_model/model.rb', line 32 model_attr :elements, default: [], referenceable_list: true |
#file_format ⇒ Symbol, NilClass (readonly)
Returns supported Archimate format [Archimate::SUPPORTED_FORMATS] or nil
.
59 |
# File 'lib/archimate/data_model/model.rb', line 59 model_attr :file_format, default: nil |
#filename ⇒ String (readonly)
Following attributes are to hold info on where the model came from
55 |
# File 'lib/archimate/data_model/model.rb', line 55 model_attr :filename, default: nil |
#id ⇒ String (readonly)
Returns unique identifier of this model.
16 |
# File 'lib/archimate/data_model/model.rb', line 16 model_attr :id |
#metadata ⇒ Metadata, NilClass (readonly)
Returns model metadata.
29 |
# File 'lib/archimate/data_model/model.rb', line 29 model_attr :metadata, default: nil |
#name ⇒ LangString (readonly)
Returns name of the model.
19 |
# File 'lib/archimate/data_model/model.rb', line 19 model_attr :name |
#namespaces ⇒ Hash (readonly)
66 |
# File 'lib/archimate/data_model/model.rb', line 66 model_attr :namespaces, default: {} |
#organizations ⇒ Array<Organization> (readonly)
38 |
# File 'lib/archimate/data_model/model.rb', line 38 model_attr :organizations, default: [], referenceable_list: true |
#properties ⇒ Array<Property> (readonly)
Returns model properties.
26 |
# File 'lib/archimate/data_model/model.rb', line 26 model_attr :properties, default: [] |
#property_definitions ⇒ Array<PropertyDefinition> (readonly)
41 |
# File 'lib/archimate/data_model/model.rb', line 41 model_attr :property_definitions, default: [], referenceable_list: true |
#relationships ⇒ Array<Relationship> (readonly)
35 |
# File 'lib/archimate/data_model/model.rb', line 35 model_attr :relationships, default: [], referenceable_list: true |
#schema_locations ⇒ Array<String> (readonly)
69 |
# File 'lib/archimate/data_model/model.rb', line 69 model_attr :schema_locations, default: [] |
#version ⇒ String, NilClass (readonly)
44 |
# File 'lib/archimate/data_model/model.rb', line 44 model_attr :version, default: nil |
#viewpoints ⇒ Array<Viewpoint> (readonly)
50 |
# File 'lib/archimate/data_model/model.rb', line 50 model_attr :viewpoints, default: [], referenceable_list: true |
Instance Method Details
#entities ⇒ Object
Called only by [Lint::DuplicateEntities]
88 89 90 |
# File 'lib/archimate/data_model/model.rb', line 88 def entities @index_hash.values end |
#find_by_class(klass) ⇒ Object
180 181 182 |
# File 'lib/archimate/data_model/model.rb', line 180 def find_by_class(klass) @index_hash.values.select { |item| item.is_a?(klass) } end |
#lookup(id) ⇒ Object
82 83 84 85 |
# File 'lib/archimate/data_model/model.rb', line 82 def lookup(id) rebuild_index(id) unless @index_hash.include?(id) @index_hash[id] end |
#make_unique_id ⇒ Object
152 153 154 155 156 157 158 |
# File 'lib/archimate/data_model/model.rb', line 152 def make_unique_id @random ||= Random.new begin unique_id = format("%08x", @random.rand(0xffffffff)) end until !@index_hash.key?(unique_id) unique_id end |
#merge_entities(master_entity, copies) ⇒ Object
this should move into either Comparison or a Mergeable class
Steps to merge merge attributes of each copy into master_entity update references of each copy to reference master_entity instead (where it makes sense) remove reference of each copy from its references
126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/archimate/data_model/model.rb', line 126 def merge_entities(master_entity, copies) copies.delete(master_entity) copies.each do |copy| master_entity.merge(copy) copy.replace_with(master_entity) # if !copy.references.empty? # puts "#{copy.class} still referenced by #{copy.references.map { |ref| ref.class.name }.join(", ")}" # end deregister(copy) end end |
#organize ⇒ Object
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.
108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/archimate/data_model/model.rb', line 108 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) unless default_organization.items.include?(item) end end self end |
#other_attributes ⇒ Array<AnyAttribute>
74 |
# File 'lib/archimate/data_model/model.rb', line 74 model_attr :other_attributes, default: [] |
#other_elements ⇒ Array<AnyElement>
72 |
# File 'lib/archimate/data_model/model.rb', line 72 model_attr :other_elements, default: [] |
#rebuild_index(missing_id = :model_creation_event) ⇒ Object
Called only by [Diff::Merge]
93 94 95 96 97 |
# File 'lib/archimate/data_model/model.rb', line 93 def rebuild_index(missing_id = :model_creation_event) return self unless missing_id @index_hash = build_index self end |
#remove_reference(item) ⇒ Object
160 161 162 163 164 165 166 167 168 169 170 171 172 |
# File 'lib/archimate/data_model/model.rb', line 160 def remove_reference(item) case item when Element elements.delete(item) when Relationship relationships.delete(item) when Diagram diagrams.delete(item) else raise "Unhandled remove reference for type #{item.class}" end organizations.each { |org| org.remove_reference(item) } end |
#replace_item_with(item, replacement) ⇒ Object
138 139 140 141 142 143 144 145 146 147 148 149 150 |
# File 'lib/archimate/data_model/model.rb', line 138 def replace_item_with(item, replacement) case item when Organization organizations.delete(item) organizations << replacement when Element elements.delete(item) elements << replacement when Relationship relationships.delete(item) relationships << replacement end end |