require 'json' module WZombi class CommandStore def initialize(path) @path = path init_file end def init_file File.write(@path, { id: 0, cmd: "" }.to_json) unless File.exist?(@path) end def current JSON.parse(File.read(@path)) end def update(cmd) data = current data["id"] += 1 data["cmd"] = cmd File.write(@path, data.to_json) end end end