Class: TdCLI::Cache
- Inherits:
-
Object
- Object
- TdCLI::Cache
- Defined in:
- lib/todoist/cache.rb
Instance Method Summary collapse
- #get(item) ⇒ Object
-
#initialize ⇒ Cache
constructor
A new instance of Cache.
-
#load ⇒ Object
load the cache from the data dir.
-
#save ⇒ Object
save the cache to the data dir.
- #set(data) ⇒ Object
Constructor Details
Instance Method Details
#get(item) ⇒ Object
20 21 22 |
# File 'lib/todoist/cache.rb', line 20 def get(item) return @_cache[item] end |
#load ⇒ Object
load the cache from the data dir
25 26 27 28 29 30 31 32 |
# 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 ⇒ Object
save the cache to the data dir
35 36 37 38 |
# 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) ⇒ Object
16 17 18 |
# File 'lib/todoist/cache.rb', line 16 def set(data) @_cache = data end |