Class: Glossarist::ConceptStore
- Inherits:
-
Object
- Object
- Glossarist::ConceptStore
show all
- Defined in:
- lib/glossarist/concept_store.rb
Defined Under Namespace
Classes: ConceptDocumentSerializer
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(adapter: :memory) ⇒ ConceptStore
Returns a new instance of ConceptStore.
29
30
31
32
33
34
|
# File 'lib/glossarist/concept_store.rb', line 29
def initialize(adapter: :memory)
@db = Lutaml::Store::DatabaseStore.new(
adapter: adapter,
models: [concept_document_registration],
)
end
|
Instance Attribute Details
#db ⇒ Object
Returns the value of attribute db.
27
28
29
|
# File 'lib/glossarist/concept_store.rb', line 27
def db
@db
end
|
Instance Method Details
#clear ⇒ Object
67
68
69
70
71
|
# File 'lib/glossarist/concept_store.rb', line 67
def clear
db.all(model: V3::ConceptDocument).each do |doc|
db.destroy(model: V3::ConceptDocument, id: doc.id)
end
end
|
#concepts ⇒ Object
55
56
57
|
# File 'lib/glossarist/concept_store.rb', line 55
def concepts
db.all(model: V3::ConceptDocument).map(&:concept)
end
|
#count ⇒ Object
59
60
61
|
# File 'lib/glossarist/concept_store.rb', line 59
def count
db.count(model: V3::ConceptDocument)
end
|
#exists?(uuid) ⇒ Boolean
63
64
65
|
# File 'lib/glossarist/concept_store.rb', line 63
def exists?(uuid)
db.exists?(model: V3::ConceptDocument, id: uuid)
end
|
#fetch(uuid) ⇒ Object
50
51
52
53
|
# File 'lib/glossarist/concept_store.rb', line 50
def fetch(uuid)
doc = db.fetch(model: V3::ConceptDocument, id: uuid)
doc&.concept
end
|
#load_glossary(path) ⇒ Object
36
37
38
39
40
41
42
43
44
45
46
47
48
|
# File 'lib/glossarist/concept_store.rb', line 36
def load_glossary(path)
documents = db.load_all(
V3::ConceptDocument, path: path, format: :yamls, layout: :grouped
)
documents.each do |doc|
concept = doc.concept
concept.uuid = doc.id
db.save(doc)
end
documents
end
|