Module: ZendeskAppsTools::Cache
- Included in:
- CommandHelpers
- Defined in:
- lib/zendesk_apps_tools/cache.rb
Constant Summary collapse
- CACHE_FILE_NAME =
'.xat'
Instance Method Summary collapse
Instance Method Details
#cache_path ⇒ Object
21 22 23 |
# File 'lib/zendesk_apps_tools/cache.rb', line 21 def cache_path @cache_path ||= File.join [:path], CACHE_FILE_NAME end |
#clear_cache ⇒ Object
17 18 19 |
# File 'lib/zendesk_apps_tools/cache.rb', line 17 def clear_cache File.delete cache_path if [:clean] && File.exist?(cache_path) end |
#fetch_cache(key) ⇒ Object
12 13 14 15 |
# File 'lib/zendesk_apps_tools/cache.rb', line 12 def fetch_cache(key) @cache ||= File.exist?(cache_path) ? JSON.parse(File.read(@cache_path)) : {} @cache[key] if @cache end |
#save_cache(hash) ⇒ Object
5 6 7 8 9 10 |
# File 'lib/zendesk_apps_tools/cache.rb', line 5 def save_cache(hash) return if [:zipfile] @cache = File.exist?(cache_path) ? JSON.parse(File.read(@cache_path)).update(hash) : hash File.open(@cache_path, 'w') { |f| f.write JSON.pretty_generate(@cache) } end |