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.



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

def initialize(base_client)
  @base_client = 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.



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

def highwater_mark
  @highwater_mark
end

Instance Method Details

#calc_config ⇒ Object



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

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



41
42
43
44
45
46
47
# File 'lib/prefab/config_loader.rb', line 41

def get_api_deltas
  configs = Prefab::Configs.new
  @api_config.each_value do |config_value|
    configs.configs << config_value
  end
  configs
end

#rm(key) ⇒ Object



37
38
39
# File 'lib/prefab/config_loader.rb', line 37

def rm(key)
  @api_config.delete key
end

#set(config) ⇒ Object



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

def set(config)
  # don't overwrite newer values
  if @api_config[config.key] && @api_config[config.key].id > config.id
    return
  end

  if config.rows.empty?
    @api_config.delete(config.key)
  else
    @api_config[config.key] = config
  end
  @highwater_mark = [config.id, @highwater_mark].max
end