Class: Glossarist::ConceptStore

Inherits:
Object
  • Object
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.



27
28
29
30
31
32
# File 'lib/glossarist/concept_store.rb', line 27

def initialize(adapter: :memory)
  @db = Lutaml::Store::DatabaseStore.new(
    adapter: adapter,
    models: [concept_document_registration],
  )
end

Instance Attribute Details

#dbObject (readonly)

Returns the value of attribute db.



25
26
27
# File 'lib/glossarist/concept_store.rb', line 25

def db
  @db
end

Instance Method Details

#clearObject



64
65
66
67
68
# File 'lib/glossarist/concept_store.rb', line 64

def clear
  db.all(model: V3::ConceptDocument).each do |doc|
    db.destroy(model: V3::ConceptDocument, id: doc.id)
  end
end

#conceptsObject



52
53
54
# File 'lib/glossarist/concept_store.rb', line 52

def concepts
  db.all(model: V3::ConceptDocument).map(&:concept)
end

#countObject



56
57
58
# File 'lib/glossarist/concept_store.rb', line 56

def count
  db.count(model: V3::ConceptDocument)
end

#exists?(uuid) ⇒ Boolean

Returns:

  • (Boolean)


60
61
62
# File 'lib/glossarist/concept_store.rb', line 60

def exists?(uuid)
  db.exists?(model: V3::ConceptDocument, id: uuid)
end

#fetch(uuid) ⇒ Object



47
48
49
50
# File 'lib/glossarist/concept_store.rb', line 47

def fetch(uuid)
  doc = db.fetch(model: V3::ConceptDocument, id: uuid)
  doc&.concept
end

#load_glossary(path) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/glossarist/concept_store.rb', line 34

def load_glossary(path)
  documents = db.load_all(
    V3::ConceptDocument, path: path, format: :yamls, layout: :grouped
  )

  documents.each do |doc|
    doc.ensure_concept_uuid!
    db.save(doc)
  end

  documents
end