Class: Supermarket::Cache
- Inherits:
-
Object
- Object
- Supermarket::Cache
- Defined in:
- lib/bundles/inspec-supermarket/cache.rb
Instance Method Summary collapse
-
#initialize ⇒ Cache
constructor
A new instance of Cache.
- #retrieve_cache ⇒ Object
- #update_cache(data) ⇒ Object
Constructor Details
#initialize ⇒ Cache
Returns a new instance of Cache.
7 8 9 10 11 12 13 14 15 |
# File 'lib/bundles/inspec-supermarket/cache.rb', line 7 def initialize @config_path = File.join(ENV['HOME'], '/.inspec') # ensure the directory is available unless File.directory?(@config_path) FileUtils.mkdir_p(@config_path) end # set cache file path @cache_file = File.join(@config_path, '/supermarket-cache.json') end |
Instance Method Details
#retrieve_cache ⇒ Object
23 24 25 26 27 28 |
# File 'lib/bundles/inspec-supermarket/cache.rb', line 23 def retrieve_cache if File.exists?(@cache_file) file = File.read(@cache_file) JSON.parse(file) end end |
#update_cache(data) ⇒ Object
17 18 19 20 21 |
# File 'lib/bundles/inspec-supermarket/cache.rb', line 17 def update_cache(data) File.open(@cache_file,"w") do |f| f.write(data.to_json) end end |