Method: Bonethug::Conf#compile_configuration

Defined in:
lib/bonethug/conf.rb

#compile_configurationObject



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/bonethug/conf.rb', line 44

def compile_configuration

  # load the defaults if we haven't loaded anything

  use_defaults if @paths.empty?

  # generate output

  out = {}
  @paths.each do |path,options|
    
    # load the file if we haven't already

    load_path path unless @loaded_paths.include? path

    # create a base fragment

    fragment_base = {}

    # create the other nodes

    if options and options.has_key? :root
      fragment = fragment_base
      nodes = options[:root].split '.'
      nodes.each_with_index do |node,i|
        fragment[node] = i == nodes.length-1 ? @config_hashes[path] : {}
        fragment = fragment[node]
      end
    else
      fragment_base = @config_hashes[path]
    end

    # output

    out = out.merge fragment_base

  end
  @compiled_hash = out
  self

end