Class: Archimate::DataModel::Model
- Inherits:
-
Object
- Object
- Archimate::DataModel::Model
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, #inspect, #pretty_print, #to_h
Constructor Details
#initialize(opts = {}) ⇒ Model
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
62
|
# File 'lib/archimate/data_model/model.rb', line 62
model_attr :archimate_version, default: :archimate_3_0
|
#diagrams ⇒ Array<Diagram>
47
|
# File 'lib/archimate/data_model/model.rb', line 47
model_attr :diagrams, default: [], referenceable_list: true
|
23
|
# File 'lib/archimate/data_model/model.rb', line 23
model_attr :documentation, default: nil
|
#elements ⇒ Array<Element>
32
|
# File 'lib/archimate/data_model/model.rb', line 32
model_attr :elements, default: [], referenceable_list: true
|
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
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
16
|
# File 'lib/archimate/data_model/model.rb', line 16
model_attr :id
|
29
|
# File 'lib/archimate/data_model/model.rb', line 29
model_attr :metadata, default: nil
|
19
|
# File 'lib/archimate/data_model/model.rb', line 19
model_attr :name
|
#namespaces ⇒ Hash
66
|
# File 'lib/archimate/data_model/model.rb', line 66
model_attr :namespaces, default: {}
|
38
|
# File 'lib/archimate/data_model/model.rb', line 38
model_attr :organizations, default: [], referenceable_list: true
|
#properties ⇒ Array<Property>
26
|
# File 'lib/archimate/data_model/model.rb', line 26
model_attr :properties, default: []
|
41
|
# File 'lib/archimate/data_model/model.rb', line 41
model_attr :property_definitions, default: [], referenceable_list: true
|
35
|
# File 'lib/archimate/data_model/model.rb', line 35
model_attr :relationships, default: [], referenceable_list: true
|
#schema_locations ⇒ Array<String>
69
|
# File 'lib/archimate/data_model/model.rb', line 69
model_attr :schema_locations, default: []
|
#version ⇒ String, NilClass
44
|
# File 'lib/archimate/data_model/model.rb', line 44
model_attr :version, default: nil
|
#viewpoints ⇒ Array<Viewpoint>
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
TODO:
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)
deregister(copy)
end
end
|
#organize ⇒ Object
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.
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
|
#to_s ⇒ Object
99
100
101
|
# File 'lib/archimate/data_model/model.rb', line 99
def to_s
"#{Archimate::Color.data_model('Model')}<#{id}>[#{Archimate::Color.color(name, %i[white underline])}]"
end
|