diff options
author | David Vazgenovich Shakaryan <dvshakaryan@gmail.com> | 2014-04-21 04:11:27 -0700 |
---|---|---|
committer | David Vazgenovich Shakaryan <dvshakaryan@gmail.com> | 2014-04-21 04:11:27 -0700 |
commit | 39dfb870d9a54d63f24a150e995b6da44f81ba43 (patch) | |
tree | e7f798d34c1055592820e22aa84ea5a96daa7564 /core/store.rb | |
parent | d6c6160df2e1872e1a0be9dfb8773c174ba4bde2 (diff) | |
download | dinobot-39dfb870d9a54d63f24a150e995b6da44f81ba43.tar.gz dinobot-39dfb870d9a54d63f24a150e995b6da44f81ba43.tar.xz |
Add simple persistent data store.
Diffstat (limited to 'core/store.rb')
-rw-r--r-- | core/store.rb | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/core/store.rb b/core/store.rb new file mode 100644 index 0000000..4d5e9a7 --- /dev/null +++ b/core/store.rb @@ -0,0 +1,29 @@ +require 'pstore' + +module Dinobot + module Core + class Store + attr_accessor :data + + def initialize(file) + @store = PStore.new(file, true) + + read + + @data ||= {} + end + + def read + @store.transaction(true) do + @data = @store[:data] + end + end + + def save + @store.transaction do + @store[:data] = @data + end + end + end + end +end |