7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
# File 'lib/nesta/config_file.rb', line 7
def set_value(key, value)
pattern = /^\s*#?\s*#{key}:.*/
replacement = "#{key}: #{value}"
configured = false
File.open(self.class.path, 'r+') do |file|
output = ''
file.each_line do |line|
if configured
output << line
else
output << line.sub(pattern, replacement)
configured = true if line =~ pattern
end
end
output << "#{replacement}\n" unless configured
file.pos = 0
file.print(output)
file.truncate(file.pos)
end
end
|