Class: Prefab::ConfigLoader

Inherits:
Object
  • Object
show all
Defined in:
lib/prefab/config_loader.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(base_client) ⇒ ConfigLoader

Returns a new instance of ConfigLoader.



7
8
9
10
11
12
13
14
# File 'lib/prefab/config_loader.rb', line 7

def initialize(base_client)
  @base_client = base_client
  @prefab_options = base_client.options
  @highwater_mark = 0
  @classpath_config = load_classpath_config
  @local_overrides = load_local_overrides
  @api_config = Concurrent::Map.new
end

Instance Attribute Details

#highwater_markObject (readonly)

Returns the value of attribute highwater_mark.



5
6
7
# File 'lib/prefab/config_loader.rb', line 5

def highwater_mark
  @highwater_mark
end

Instance Method Details

#calc_configObject



16
17
18
19
20
21
22
# File 'lib/prefab/config_loader.rb', line 16

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_deltasObject



44
45
46
47
48
49
50
# File 'lib/prefab/config_loader.rb', line 44

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



40
41
42
# File 'lib/prefab/config_loader.rb', line 40

def rm(key)
  @api_config.delete key
end

#set(config, source) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/prefab/config_loader.rb', line 24

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]
      @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