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_markObject (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_configObject



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].value
  end
  rtn = rtn.merge(@local_overrides)
  rtn
end

#get_api_deltasObject



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

def get_api_deltas
  deltas = Prefab::ConfigDeltas.new
  @api_config.each_value do |config_value|
    deltas.deltas << config_value
  end
  deltas
end

#rm(key) ⇒ Object



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

def rm(key)
  @api_config.delete key
end

#set(delta) ⇒ Object



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

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

  if delta.value.nil?
    @api_config.delete(delta.key)
  else
    @api_config[delta.key] = delta
  end
  @highwater_mark = [delta.id, @highwater_mark].max
end