require 'jrjackson' module Anschel class Store def initialize path, log @path = path || '/tmp/anschel.db' @hash = nil if File.exist? @path @hash = JrJackson::Json.load \ File.read(@path), symbolize_keys: true end @hash ||= {} log.info event: 'stats-loaded' end def [] k ; @hash[k] end def []= k,v ; @hash[k] = v ; save end def save File.open(@path, 'w') do |f| f.puts JrJackson::Json.dump(@hash) end end end end