Class: Prefab::ConfigLoader
- Inherits:
-
Object
- Object
- Prefab::ConfigLoader
- Defined in:
- lib/prefab/config_loader.rb
Instance Attribute Summary collapse
-
#highwater_mark ⇒ Object
readonly
Returns the value of attribute highwater_mark.
Instance Method Summary collapse
- #calc_config ⇒ Object
- #get_api_deltas ⇒ Object
-
#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.
8 9 10 11 12 13 14 15 |
# File 'lib/prefab/config_loader.rb', line 8 def initialize(base_client) @base_client = base_client @prefab_options = base_client. @highwater_mark = 0 @classpath_config = load_classpath_config @local_overrides = load_local_overrides @api_config = Concurrent::Map.new end |
Instance Attribute Details
#highwater_mark ⇒ Object (readonly)
Returns the value of attribute highwater_mark.
6 7 8 |
# File 'lib/prefab/config_loader.rb', line 6 def highwater_mark @highwater_mark end |
Instance Method Details
#calc_config ⇒ Object
17 18 19 20 21 22 23 24 |
# File 'lib/prefab/config_loader.rb', line 17 def calc_config rtn = @classpath_config.clone @api_config.each_key do |k| rtn[k] = @api_config[k] end rtn = rtn.merge(@local_overrides) rtn end |
#get_api_deltas ⇒ Object
47 48 49 50 51 52 53 |
# File 'lib/prefab/config_loader.rb', line 47 def get_api_deltas configs = Prefab::Configs.new @api_config.each_value do |config_value| configs.configs << config_value[:config] end configs end |
#rm(key) ⇒ Object
43 44 45 |
# File 'lib/prefab/config_loader.rb', line 43 def rm(key) @api_config.delete key end |
#set(config, source) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/prefab/config_loader.rb', line 26 def set(config, source) # don't overwrite newer values if @api_config[config.key] && @api_config[config.key][:config].id >= config.id return end if config.rows.empty? @api_config.delete(config.key) else if @api_config[config.key] @base_client.log_internal Logger::DEBUG, "Replace #{config.key} with value from #{source} #{ @api_config[config.key][:config].id} -> #{config.id}" end @api_config[config.key] = { source: source, config: config } end @highwater_mark = [config.id, @highwater_mark].max end |