Class: Prefab::ConfigLoader
- Inherits:
-
Object
- Object
- Prefab::ConfigLoader
- Defined in:
- lib/prefab/config_loader.rb
Constant Summary collapse
- LOG =
Prefab::InternalLogger.new(ConfigLoader)
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.
9 10 11 12 13 14 15 16 |
# File 'lib/prefab/config_loader.rb', line 9 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.
7 8 9 |
# File 'lib/prefab/config_loader.rb', line 7 def highwater_mark @highwater_mark end |
Instance Method Details
#calc_config ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/prefab/config_loader.rb', line 18 def calc_config rtn = @classpath_config.clone @api_config.each_key do |k| rtn[k] = @api_config[k] end rtn.merge(@local_overrides) end |
#get_api_deltas ⇒ Object
46 47 48 49 50 51 52 |
# File 'lib/prefab/config_loader.rb', line 46 def get_api_deltas configs = PrefabProto::Configs.new @api_config.each_value do |config_value| configs.configs << config_value[:config] end configs end |
#rm(key) ⇒ Object
42 43 44 |
# File 'lib/prefab/config_loader.rb', line 42 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 |
# File 'lib/prefab/config_loader.rb', line 26 def set(config, source) # don't overwrite newer values return if @api_config[config.key] && @api_config[config.key][:config].id >= config.id if config.rows.empty? @api_config.delete(config.key) else if @api_config[config.key] LOG.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 |