Class: Glossarist::ConceptStore

Inherits:
Object
  • Object
show all
Defined in:
lib/glossarist/concept_store.rb

Defined Under Namespace

Classes: Serializer

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(adapter: :memory) ⇒ ConceptStore

Returns a new instance of ConceptStore.



32
33
34
35
36
37
# File 'lib/glossarist/concept_store.rb', line 32

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

Instance Attribute Details

#dbObject (readonly)

Returns the value of attribute db.



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

def db
  @db
end

Instance Method Details

#allObject



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

def all
  db.all(model: ManagedConcept)
end

#clearObject



71
72
73
# File 'lib/glossarist/concept_store.rb', line 71

def clear
  all.each { |concept| delete(concept.uuid) }
end

#countObject



63
64
65
# File 'lib/glossarist/concept_store.rb', line 63

def count
  db.count(model: ManagedConcept)
end

#delete(uuid) ⇒ Object



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

def delete(uuid)
  db.destroy(model: ManagedConcept, uuid: uuid)
end

#exists?(uuid) ⇒ Boolean

Returns:

  • (Boolean)


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

def exists?(uuid)
  db.exists?(model: ManagedConcept, uuid: uuid)
end

#fetch(uuid) ⇒ Object



43
44
45
# File 'lib/glossarist/concept_store.rb', line 43

def fetch(uuid)
  db.fetch(model: ManagedConcept, uuid: uuid)
end

#fetch_by_id(identifier) ⇒ Object



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

def fetch_by_id(identifier)
  db.where(model: ManagedConcept, identifier: identifier).first
end

#load_from_directory(path, format: :yaml, layout: :separate) ⇒ Object



75
76
77
# File 'lib/glossarist/concept_store.rb', line 75

def load_from_directory(path, format: :yaml, layout: :separate)
  db.import_all(ManagedConcept, path: path, format: format, layout: layout)
end

#save(concept) ⇒ Object



39
40
41
# File 'lib/glossarist/concept_store.rb', line 39

def save(concept)
  db.save(concept)
end

#save_to_directory(path, format: :yaml, layout: :separate) ⇒ Object



79
80
81
# File 'lib/glossarist/concept_store.rb', line 79

def save_to_directory(path, format: :yaml, layout: :separate)
  db.save_all(all, path: path, format: format, layout: layout)
end

#update(uuid, **attributes) ⇒ Object



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

def update(uuid, **attributes)
  db.update(model: ManagedConcept, uuid: uuid, attributes: attributes)
end