Class: Quonfig::ConfigLoader
- Inherits:
-
Object
- Object
- Quonfig::ConfigLoader
- Defined in:
- lib/quonfig/config_loader.rb
Constant Summary collapse
- LOG =
Quonfig::InternalLogger.new(self)
- CONFIGS_PATH =
'/api/v2/configs'
Instance Attribute Summary collapse
-
#etag ⇒ Object
readonly
Returns the value of attribute etag.
Instance Method Summary collapse
- #calc_config ⇒ Object
-
#fetch! ⇒ Object
Fetch configs from /api/v2/configs with ETag / If-None-Match caching.
-
#initialize(base_client) ⇒ ConfigLoader
constructor
A new instance of ConfigLoader.
- #rm(key) ⇒ Object
- #set(config, source) ⇒ Object
Constructor Details
#initialize(base_client) ⇒ ConfigLoader
Returns a new instance of ConfigLoader.
13 14 15 16 17 18 |
# File 'lib/quonfig/config_loader.rb', line 13 def initialize(base_client) @base_client = base_client @options = base_client. @api_config = Concurrent::Map.new @etag = nil end |
Instance Attribute Details
#etag ⇒ Object (readonly)
Returns the value of attribute etag.
11 12 13 |
# File 'lib/quonfig/config_loader.rb', line 11 def etag @etag end |
Instance Method Details
#calc_config ⇒ Object
34 35 36 37 38 39 40 |
# File 'lib/quonfig/config_loader.rb', line 34 def calc_config rtn = {} @api_config.each_key do |k| rtn[k] = @api_config[k] end rtn end |
#fetch! ⇒ Object
Fetch configs from /api/v2/configs with ETag / If-None-Match caching.
Returns one of:
:updated — 200 response; @api_config and @etag replaced
:not_modified — 304 response; cache still valid
:failed — every configured source failed
26 27 28 29 30 31 32 |
# File 'lib/quonfig/config_loader.rb', line 26 def fetch! Array(@options.config_api_urls).each do |api_url| result = fetch_from(api_url) return result if result != :failed end :failed end |
#rm(key) ⇒ Object
46 47 48 |
# File 'lib/quonfig/config_loader.rb', line 46 def rm(key) @api_config.delete(key) end |
#set(config, source) ⇒ Object
42 43 44 |
# File 'lib/quonfig/config_loader.rb', line 42 def set(config, source) @api_config[config.key] = { source: source, config: config } end |