Sha256: 8a0810900b42457244c9aebc23308235f89f5fb4f8344ec76b4c0d17b3eeb74f

Contents?: true

Size: 796 Bytes

Versions: 1

Compression:

Stored size: 796 Bytes

Contents

require 'pstore'

class SparaDisk
  def initialize(name)
    @store = PStore.new(name)
  end

  def set(key, value)
    @store.transaction { @store[key] = value }
  end

  def get(key)
    @store.transaction(true) { @store.fetch(key, nil) }
  end

  def del(key)
    @store.transaction { @store.delete(key) }
  end

  def keys
    @store.transaction(true) { @store.roots }
  end

  def vals
    @store.transaction(true) do
      # @store.instance_variable_get(:@table).values
      @store.roots.inject([]) do |values, key|
        values.push(@store[key])
        values
      end
    end
  end

  def all
    @store.transaction(true) do
      # @store.instance_variable_get(:@table)
      @store.roots.inject({}) do |db, key|
        db[key] = @store[key]
        db
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
spara-0.0.1 lib/spara/spara_disk.rb