Sha256: d0f6e86231c7b171584c351ef1a9c1f9ff493fa64b04b3f0e13d8299d2a4cae3

Contents?: true

Size: 531 Bytes

Versions: 3

Compression:

Stored size: 531 Bytes

Contents

require "pstore"
require "fileutils"

module Ykxutils
  class Pstorex
    def initialize(store_dir, dump_file="pstore.dump")
      FileUtils.mkdir_p(store_dir)
      @store_db = PStore.new(Pathname.new(store_dir).join(dump_file))
    end

    def fetch(key, default_value)
      value = default_value
      @store_db.transaction do
        value = @store_db.fetch(key, default_value)
      end
      value
    end

    def store(key, value)
      @store_db.transaction do
        @store_db[key] = value
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
ykxutils-0.1.5 lib/ykxutils/pstorex.rb
ykxutils-0.1.4 lib/ykxutils/pstorex.rb
ykxutils-0.1.3 lib/ykxutils/pstorex.rb