Class: Opencdd::Database
- Inherits:
-
Object
show all
- Includes:
- Enumerable, Finalization, Mutations, ParcelIntegration, Persistence, Queries
- Defined in:
- lib/opencdd/database.rb,
lib/opencdd/database/queries.rb,
lib/opencdd/database/mutations.rb,
lib/opencdd/database/persistence.rb,
lib/opencdd/database/finalization.rb,
lib/opencdd/database/parcel_integration.rb
Defined Under Namespace
Modules: Finalization, Mutations, ParcelIntegration, Persistence, Queries
Classes: Dictionary
Constant Summary
collapse
- FORCED_META_CLASSES =
%w[MDC_C002 MDC_C003].freeze
- PARCEL_ID_PATTERN =
/\A[A-Z0-9-]+\z/.freeze
Constants included
from Mutations
Mutations::REFERENCE_VALUE_KINDS
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
#save_to_directory, #semantically_equal?, #to_yaml
Methods included from Mutations
#apply_change_request, #apply_view_control, #merge, #remove_by_irdi, #rename_entity
#each_reference_collection, #finalize!, #normalize_reference_collections!, #rebuild_symbol_table!
Methods included from Queries
#categorical_classes, #class_tree, #classes_with_property, #coerce_entity, #coerce_irdi, #composition_tree, #effective_properties, #find, #find_all_by_code, #find_by_code, #find_by_name, #functions_involving, #instances_of, #properties_of, #relation_tree, #relations_for, #resolve_reference, #root_classes, #terms_of, #valid_class_reference?, #value_list_identifier_of, #value_list_of
#add_dictionary, #add_workbook, #dictionaries, #drop_dictionary, #register_external_sheet
Constructor Details
Returns a new instance of Database.
56
57
58
59
60
61
62
63
64
65
66
|
# File 'lib/opencdd/database.rb', line 56
def initialize
@entities_by_irdi = {}
@entities_by_code = Hash.new { |h, k| h[k] = [] }
@entities_by_type = Hash.new { |h, k| h[k] = [] }
@workbooks = []
@unresolved_refs = []
@class_by_property_irdi = nil
@symbol_table = {}
@alias_table = Opencdd::AliasTable.new(defaults: true)
@entity_sources = {}
end
|
Instance Attribute Details
#alias_table ⇒ Object
Returns the value of attribute alias_table.
30
31
32
|
# File 'lib/opencdd/database.rb', line 30
def alias_table
@alias_table
end
|
#unresolved_refs ⇒ Object
Returns the value of attribute unresolved_refs.
30
31
32
|
# File 'lib/opencdd/database.rb', line 30
def unresolved_refs
@unresolved_refs
end
|
#workbooks ⇒ Object
Returns the value of attribute workbooks.
30
31
32
|
# File 'lib/opencdd/database.rb', line 30
def workbooks
@workbooks
end
|
Class Method Details
.from_yaml(yaml) ⇒ Object
48
49
50
|
# File 'lib/opencdd/database.rb', line 48
def self.from_yaml(yaml)
Opencdd::Model::YamlDatabase.from_yaml(yaml).to_database
end
|
.load_flat_dir(path) ⇒ Object
.load_from_directory(path) ⇒ Object
.load_sharded_dir(path) ⇒ Object
.load_workbook(path) ⇒ Object
Instance Method Details
#add_entity(entity) ⇒ Object
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
# File 'lib/opencdd/database.rb', line 68
def add_entity(entity)
irdi = entity.irdi
if irdi.nil?
@unresolved_refs << [nil, entity]
return self
end
if @entities_by_irdi.key?(irdi)
existing = @entities_by_irdi[irdi]
return self if existing.properties == entity.properties
warn "Duplicate IRDI #{irdi} — overwriting"
end
@entities_by_irdi[irdi] = entity
@entities_by_code[irdi.code] << entity if irdi.code
@entities_by_type[entity.type] << entity if entity.type
register_entity_symbols(entity)
if entity.is_a?(Opencdd::Klass)
entity.attach_database(self)
end
self
end
|
#classes ⇒ Object
105
|
# File 'lib/opencdd/database.rb', line 105
def classes ; @entities_by_type[:class] || [] ; end
|
#count(type = nil) ⇒ Object
121
122
123
|
# File 'lib/opencdd/database.rb', line 121
def count(type = nil)
type ? (@entities_by_type[type] || []).size : @entities_by_irdi.size
end
|
#each(&block) ⇒ Object
125
126
127
|
# File 'lib/opencdd/database.rb', line 125
def each(&block)
@entities_by_irdi.each_value(&block)
end
|
#entities ⇒ Object
117
118
119
|
# File 'lib/opencdd/database.rb', line 117
def entities
@entities_by_irdi.values
end
|
#entities_of_type(type) ⇒ Object
113
114
115
|
# File 'lib/opencdd/database.rb', line 113
def entities_of_type(type)
@entities_by_type[type.to_sym] || []
end
|
#properties ⇒ Object
106
|
# File 'lib/opencdd/database.rb', line 106
def properties ; @entities_by_type[:property] || [] ; end
|
#register_entity_symbols(entity) ⇒ Object
97
98
99
100
101
102
103
|
# File 'lib/opencdd/database.rb', line 97
def register_entity_symbols(entity)
name = entity.is_a?(Opencdd::Entity) ? entity.preferred_name : nil
bind_symbol(name, entity) if name
code = entity.code
bind_symbol(code, entity) if code
self
end
|
#register_symbol(name, entity) ⇒ Object
93
94
95
|
# File 'lib/opencdd/database.rb', line 93
def register_symbol(name, entity)
bind_symbol(name, entity)
end
|
#relations ⇒ Object
110
|
# File 'lib/opencdd/database.rb', line 110
def relations ; @entities_by_type[:relation] || [] ; end
|
#to_s ⇒ Object
Also known as:
inspect
129
130
131
132
133
|
# File 'lib/opencdd/database.rb', line 129
def to_s
"#<#{self.class.name} classes=#{classes.size} properties=#{properties.size} " \
"units=#{units.size} value_lists=#{value_lists.size} value_terms=#{value_terms.size} " \
"relations=#{relations.size}>"
end
|
#units ⇒ Object
107
|
# File 'lib/opencdd/database.rb', line 107
def units ; @entities_by_type[:unit] || [] ; end
|
#value_lists ⇒ Object
108
|
# File 'lib/opencdd/database.rb', line 108
def value_lists ; @entities_by_type[:value_list] || [] ; end
|
#value_terms ⇒ Object
109
|
# File 'lib/opencdd/database.rb', line 109
def value_terms ; @entities_by_type[:value_term] || [] ; end
|
#view_controls ⇒ Object
111
|
# File 'lib/opencdd/database.rb', line 111
def view_controls ; @entities_by_type[:view_control] || [] ; end
|