Class: WeatherSage::CLI::Env::Cache

Inherits:
HTTP::Cache show all
Defined in:
lib/weather-sage/cli/env/cache.rb

Overview

Create HTTP::Cache fron environment variables.

Constant Summary collapse

DEFAULT_PATH =

Default cache path.

'~/.config/weather-sage/http-cache.pstore'

Instance Attribute Summary

Attributes inherited from HTTP::Cache

#path

Instance Method Summary collapse

Methods inherited from HTTP::Cache

#get, #key?

Constructor Details

#initialize(env, log) ⇒ Cache

Create HTTP::Cache fron environment variables.

Uses the following environment variables:

  • WEATHER_SAGE_CACHE_PATH: Path to HTTP cache file. Defaults to “~/.config/weather-sage/http-cache.pstore”.



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/weather-sage/cli/env/cache.rb', line 20

def initialize(env, log)
  # get cache path
  unless path = env.get('CACHE_PATH')
    # use default cache path
    path = File.expand_path(DEFAULT_PATH)

    # create parent directories (if necessary)
    FileUtils.mkdir_p(File.dirname(path))
  end

  # log cache path
  log.info('Env::Cache#initialize') do
    'path = %p' % [path]
  end

  # return cache instance
  super(path, log)
end