class Raykit::Log
def get_command_time(command)
def get_command_time(command) if key?("command_times") command_times = self["command_times"] return DateTime.parse(command_times[command]) if command_times.key?(command) end nil end
def initialize(filename)
def initialize(filename) @filename = filename dir = File.dirname(@filename) FileUtils.mkdir_p(dir) unless Dir.exist?(dir) if File.exist?(@filename) begin data = JSON.parse(File.read(filename)) data.each do |k, v| self[k] = v end rescue StandardError end end end
def save
def save File.open(@filename, "w") { |f| f.write(JSON.generate(self)) } end
def update_command_time(command, timestamp)
def update_command_time(command, timestamp) command_times = {} command_times = self["command_times"] if key?("command_times") command_times.delete(command) if command_times.key?(command) command_times[command] = timestamp.iso8601 self["command_times"] = command_times save end