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



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

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

#conceptsObject



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

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

#countObject



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

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

#exists?(uuid) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#fetch(uuid) ⇒ Object



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

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
46
# 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|
    concept = doc.concept
    concept.uuid = doc.id
    db.save(doc)
  end

  documents
end