Top Level Namespace

Defined Under Namespace

Classes: Array

Instance Method Summary collapse

Instance Method Details

#parse_configuration(file) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/hooks/post-reset.rb', line 6

def parse_configuration(file)
  config = {}
  current = nil

  File.open(file).each_line do |line|
    case line
    when /^\[(\w+)(?: "(.+)")\]/
      key, subkey = $1, $2
      current = (config[key] ||= {})
      current = (current[subkey] ||= {}) if subkey
    else
      key, value = line.strip.split(' = ')
      current[key] = value
    end
  end
  
  config
end