Class: RST::Persistent::DiskStore
- Defined in:
- lib/modules/persistent/disk_store.rb
Overview
#DiskStore is responsible to save an Array of objects persistently to the disk - PStore is used to effort this.
Instance Attribute Summary collapse
-
#filename ⇒ Object
readonly
- String
-
filename - used for PStore (no path! filename only).
Instance Method Summary collapse
- #all ⇒ Array
-
#delete! ⇒ Object
Delete the store.
-
#initialize(_filename = DEFAULT_STORE_FILENAME, args = {}) ⇒ DiskStore
constructor
The first argument is the filename Following args are passed to base-class.
-
#path ⇒ String
Full path of PStore-file.
-
#update(object) ⇒ Object
Find and update or add object to the store.
Methods inherited from Store
#-, #<<, #create, #find, #first
Constructor Details
#initialize(_filename = DEFAULT_STORE_FILENAME, args = {}) ⇒ DiskStore
The first argument is the filename Following args are passed to base-class
25 26 27 28 |
# File 'lib/modules/persistent/disk_store.rb', line 25 def initialize(_filename=DEFAULT_STORE_FILENAME,args={}) @filename = _filename super(args) end |
Instance Attribute Details
#filename ⇒ Object (readonly)
- String
-
filename - used for PStore (no path! filename only)
13 14 15 |
# File 'lib/modules/persistent/disk_store.rb', line 13 def filename @filename end |
Instance Method Details
#all ⇒ Array
TODO:
This is bad for performance and memory - refactor!
37 38 39 40 41 42 43 44 45 |
# File 'lib/modules/persistent/disk_store.rb', line 37 def all _all = [] @store.transaction(true) do |s| s.roots.each do |_r| _all << s[_r] end end _all end |
#delete! ⇒ Object
Delete the store
48 49 50 |
# File 'lib/modules/persistent/disk_store.rb', line 48 def delete! File.unlink(store_path) end |
#path ⇒ String
Returns full path of PStore-file.
31 32 33 |
# File 'lib/modules/persistent/disk_store.rb', line 31 def path @store.path end |
#update(object) ⇒ Object
Find and update or add object to the store.
54 55 56 57 58 |
# File 'lib/modules/persistent/disk_store.rb', line 54 def update(object) @store.transaction do |s| s[object.id] = object end end |