lib/spiderfw/config/configuration_editor.rb in spiderfw-0.6.5 vs lib/spiderfw/config/configuration_editor.rb in spiderfw-0.6.6
- old
+ new
@@ -1,5 +1,7 @@
+require 'fileutils'
+
module Spider
class ConfigurationEditor
def initialize
@@ -78,17 +80,17 @@
def save
def commit_ml(res, key, val, curr)
if curr
+ curr.instance_eval("def to_yaml_style; :multiline; end")
res << {key => curr}.to_yaml.split("\n")[2..-1].join("\n") + "\n"
else
res << val
end
end
-
@changed.each do |file, data|
dirname = File.dirname(file)
basename = File.basename(file)
tmp_file = File.join(dirname, ".#{basename}.editor")
File.open(file) do |f|
@@ -109,11 +111,11 @@
add_next.each do |l|
res << indent + l + "\n"
end
add_next = nil
end
- if line =~ /(\s*)(\w[^:]+):\s*([\S]+)?$/
+ if line =~ /(\s*)(\w[^:]+):\s*(.+)?$/
indent = $1
key = $2
value = $3
unless curr_val.empty?
commit_ml(res, last_key, curr_val, curr[last_key])
@@ -147,10 +149,11 @@
curr = curr[key] if curr
if value
if curr
res << indent
+ curr.instance_eval("def to_yaml_style; :inline; end")
res << {key => curr}.to_yaml.split("\n")[1..-1].join("\n") + "\n"
else
res << line
end
else
@@ -184,11 +187,11 @@
res << l + "\n"
end
end
res.close
- File.mv(file, "#{file}.bak")
- File.mv(tmp_file, file)
+ FileUtils.mv(file, "#{file}.bak")
+ FileUtils.mv(tmp_file, file)
end
end
end
end
\ No newline at end of file