Class: Ykxutils::Pstorex

Inherits:
Object
  • Object
show all
Defined in:
lib/ykxutils/pstorex.rb

Instance Method Summary collapse

Constructor Details

#initialize(store_dir, dump_file = "pstore.dump") ⇒ Pstorex

Returns a new instance of Pstorex.



6
7
8
9
# File 'lib/ykxutils/pstorex.rb', line 6

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

Instance Method Details

#delete(key) ⇒ Object



25
26
27
28
29
# File 'lib/ykxutils/pstorex.rb', line 25

def delete(key)
  @store_db.transaction do
    @store_db.delete(key)
  end
end

#fetch(key, default_value) ⇒ Object



11
12
13
14
15
16
17
# File 'lib/ykxutils/pstorex.rb', line 11

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

#store(key, value) ⇒ Object



19
20
21
22
23
# File 'lib/ykxutils/pstorex.rb', line 19

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