class Adalog::PStoreRepo

Attributes

storage[R]

Public Class Methods

new(path, **repo_options) click to toggle source
# File lib/adalog/pstore_repo.rb, line 8
def initialize(path, **repo_options)
  @storage  = PStore.new(path, true)
end

Public Instance Methods

all() click to toggle source
# 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!() click to toggle source
# 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) click to toggle source
# File lib/adalog/pstore_repo.rb, line 13
def fetch(**options)
  all
end
insert(entry = nil, **options) click to toggle source
# File lib/adalog/pstore_repo.rb, line 27
def insert(entry = nil, **options)
  converted_entry = Adalog::Entry.build(entry, **options)
  if converted_entry.valid?
    insert_into_storage(converted_entry)
    [:ok, converted_entry]
  else
    [:error, converted_entry.errors]
  end
end