Class: ZendeskAppsTools::Cache
- Inherits:
-
Object
- Object
- ZendeskAppsTools::Cache
- Defined in:
- lib/zendesk_apps_tools/cache.rb
Constant Summary collapse
- CACHE_FILE_NAME =
'.zat'
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #clear ⇒ Object
- #fetch(key, subdomain = nil) ⇒ Object
-
#initialize(options) ⇒ Cache
constructor
A new instance of Cache.
- #save(hash) ⇒ Object
Constructor Details
#initialize(options) ⇒ Cache
Returns a new instance of Cache.
10 11 12 |
# File 'lib/zendesk_apps_tools/cache.rb', line 10 def initialize() @options = end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
8 9 10 |
# File 'lib/zendesk_apps_tools/cache.rb', line 8 def @options end |
Instance Method Details
#clear ⇒ Object
26 27 28 |
# File 'lib/zendesk_apps_tools/cache.rb', line 26 def clear File.delete local_cache_path if [:clean] && File.exist?(local_cache_path) end |
#fetch(key, subdomain = nil) ⇒ Object
21 22 23 24 |
# File 'lib/zendesk_apps_tools/cache.rb', line 21 def fetch(key, subdomain = nil) # drop the default_proc and replace with Hash#dig if older Ruby versions are unsupported local_cache[key] || global_cache[subdomain][key] || global_cache['default'][key] end |
#save(hash) ⇒ Object
14 15 16 17 18 19 |
# File 'lib/zendesk_apps_tools/cache.rb', line 14 def save(hash) return if [:zipfile] local_cache.update(hash) File.open(local_cache_path, 'w') { |f| f.write JSON.pretty_generate(local_cache) } end |