From 39dfb870d9a54d63f24a150e995b6da44f81ba43 Mon Sep 17 00:00:00 2001 From: David Vazgenovich Shakaryan Date: Mon, 21 Apr 2014 04:11:27 -0700 Subject: Add simple persistent data store. --- core/store.rb | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 core/store.rb (limited to 'core/store.rb') 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 -- cgit v1.2.3-70-g09d2