Class: ObStore::FileStore

Inherits:
Object
  • Object
show all
Defined in:
lib/obstore/filestore.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ FileStore

Returns a new instance of FileStore.



16
17
18
19
20
21
22
# File 'lib/obstore/filestore.rb', line 16

def initialize(opts={})
  opts[:database] ||= "./tmp/obstore.db"
  opts[:threadsafe] ||= true
  opts[:atomic_writes] ||= false
  @store = PStore.new(opts[:database], opts[:threadsafe])
  @store.ultra_safe = opts[:atomic_writes]
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth, *args, &block) ⇒ Object (private)



80
81
82
83
84
85
86
87
88
# File 'lib/obstore/filestore.rb', line 80

def method_missing(meth, *args, &block)
  if meth.to_s =~ /^(.+)=$/
    store_data_by_key($1, *args)
  elsif meth.to_s =~ /^(.+)$/
    fetch_data_by_key($1)
  else
    super
  end
end

Instance Attribute Details

#storeObject

Returns the value of attribute store.



14
15
16
# File 'lib/obstore/filestore.rb', line 14

def store
  @store
end

Instance Method Details

#compact!Object

removes stale records from the pstore db



25
26
27
28
29
30
31
32
33
34
# File 'lib/obstore/filestore.rb', line 25

def compact!
  keys = []
  @store.transaction do
    keys = @store.roots
  end
  keys.each do |key|
    fetch_data_by_key key.to_sym # just fetching the stale items deletes them
  end
  return true
end