Class: ConfigLogic::TreeCache

Inherits:
Cache
  • Object
show all
Defined in:
lib/config_logic/tree_cache.rb

Constant Summary

Constants included from Logger::Colors

Logger::Colors::BLUE, Logger::Colors::GREEN, Logger::Colors::RED, Logger::Colors::RESET, Logger::Colors::YELLOW

Instance Method Summary collapse

Methods included from Logger

#log

Constructor Details

#initialize(load_paths, params = {}) ⇒ TreeCache

Returns a new instance of TreeCache.



3
4
5
6
7
8
9
10
# File 'lib/config_logic/tree_cache.rb', line 3

def initialize(load_paths, params = {})
  @global_logic = params.inject([]) do |a, (type_name, elements)|
    type_name = type_name.to_s.singularize
    type = ConfigLogic::LogicElement.name_to_type(type_name)
    type ? a << elements.map { |settings| type.new(settings) } : a
  end.flatten
  super
end

Instance Method Details

#[](*key_path) ⇒ Object



12
13
14
15
16
17
# File 'lib/config_logic/tree_cache.rb', line 12

def [](*key_path)
  return @cache if key_path.blank?
  key_path.inject(@cache) do |val, key|
    val[key] if val
  end
end

#insert_logic_element(element, node) ⇒ Object



29
30
31
32
33
34
35
36
37
38
# File 'lib/config_logic/tree_cache.rb', line 29

def insert_logic_element(element, node)
  input_names = element.input_names
  input_names.each do |input_name|
    element.set_input(input_name, node[input_name])
  end
  log.debug "inserted logic element:\n#{element.pretty_inspect}"

  node[element.name] = element.static? ? element.output : element
  prune!(node, input_names)
end

#reload!(params = {}) ⇒ Object



19
20
21
22
23
24
25
26
27
# File 'lib/config_logic/tree_cache.rb', line 19

def reload!(params = {})
  @cache = rebuild_primary_cache(params)
  unless @cache.empty?
    trim_cache! unless params[:no_trim]
    @flat_cache = flatten_tree_cache
    apply_global_logic
  end
  super
end