Class: Adalog::PStoreRepo
- Inherits:
-
Object
- Object
- Adalog::PStoreRepo
- Defined in:
- lib/adalog/pstore_repo.rb
Instance Attribute Summary collapse
-
#storage ⇒ Object
readonly
Returns the value of attribute storage.
Instance Method Summary collapse
- #all ⇒ Object
- #clear! ⇒ Object
- #fetch(**options) ⇒ Object
-
#initialize(path, **repo_options) ⇒ PStoreRepo
constructor
A new instance of PStoreRepo.
- #insert(entry = nil, **options) ⇒ Object
Constructor Details
#initialize(path, **repo_options) ⇒ PStoreRepo
Returns a new instance of PStoreRepo.
8 9 10 |
# File 'lib/adalog/pstore_repo.rb', line 8 def initialize(path, **) @storage = PStore.new(path, true) end |
Instance Attribute Details
#storage ⇒ Object (readonly)
Returns the value of attribute storage.
6 7 8 |
# File 'lib/adalog/pstore_repo.rb', line 6 def storage @storage end |
Instance Method Details
#all ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/adalog/pstore_repo.rb', line 18 def all storage.transaction do storage.roots.flat_map do |key| storage.fetch(key, []) end end.reverse end |
#clear! ⇒ Object
38 39 40 41 42 43 44 45 46 |
# File 'lib/adalog/pstore_repo.rb', line 38 def clear! storage.transaction do all_keys = storage.roots all_keys.each do |key| storage.delete(key) end end :ok end |
#fetch(**options) ⇒ Object
13 14 15 |
# File 'lib/adalog/pstore_repo.rb', line 13 def fetch(**) all end |
#insert(entry = nil, **options) ⇒ Object
27 28 29 30 31 32 33 34 35 |
# File 'lib/adalog/pstore_repo.rb', line 27 def insert(entry = nil, **) converted_entry = Adalog::Entry.build(entry, **) if converted_entry.valid? insert_into_storage(converted_entry) [:ok, converted_entry] else [:error, converted_entry.errors] end end |