aboutsummaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorDavid Vazgenovich Shakaryan <dvshakaryan@gmail.com>2014-04-21 04:11:27 -0700
committerDavid Vazgenovich Shakaryan <dvshakaryan@gmail.com>2014-04-21 04:11:27 -0700
commit39dfb870d9a54d63f24a150e995b6da44f81ba43 (patch)
treee7f798d34c1055592820e22aa84ea5a96daa7564 /core
parentd6c6160df2e1872e1a0be9dfb8773c174ba4bde2 (diff)
downloaddinobot-39dfb870d9a54d63f24a150e995b6da44f81ba43.tar.gz
dinobot-39dfb870d9a54d63f24a150e995b6da44f81ba43.tar.xz
Add simple persistent data store.
Diffstat (limited to 'core')
-rw-r--r--core/store.rb29
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