4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
# File 'lib/config/parser.rb', line 4
def settings(file_path, overrides)
config_hash = { }
overrides = overrides.map { |o| o.to_sym }
begin
File.open(file_path).each do |line|
group = line.match(/^\[(\S+)\]/)
kv = line.match(/(\w+)\s*=\s*["|']*([^"'\r\n]*)["|']*/)
override = line.match(/(\w+)<(\w+)>\s*=\s*["|']*([^"'\r\n]*)["|']*/)
if !group.nil?
config_hash[group[1]] = {}
elsif !kv.nil?
config_hash[config_hash.keys.last][kv[1]] = convert(kv[2])
elsif !override.nil?
if overrides.include? override[2].to_sym
config_hash[config_hash.keys.last][override[1].to_sym] = convert(override[3])
end
end
config_hash[config_hash.keys.last].symbolize_keys!
end
config_hash.symbolize_keys!
rescue Exception => e
puts "Caught exception: #{e}, unable to load configuration file"
end
end
|