class TdCLI::Cache
Public Class Methods
new()
click to toggle source
# File lib/todoist/cache.rb, line 6 def initialize @_cache = {} unless File.directory?(DATA_DIR) FileUtils.mkdir(DATA_DIR) end @file_path = File.join(DATA_DIR, 'cache.json') load() end
Public Instance Methods
get(item)
click to toggle source
# File lib/todoist/cache.rb, line 20 def get(item) return @_cache[item] end
load()
click to toggle source
load the cache from the data dir
# File lib/todoist/cache.rb, line 25 def load if File.exist?(@file_path) @_cache = JSON File.open(@file_path, &:read).strip else $stderr.puts "#{@file_path} does not exist" end end
save()
click to toggle source
save the cache to the data dir
# File lib/todoist/cache.rb, line 35 def save cache_json = JSON.generate @_cache File.open(@file_path, 'w') { |file| file.write(cache_json) } end
set(data)
click to toggle source
# File lib/todoist/cache.rb, line 16 def set(data) @_cache = data end