support various quoting styles in .env

This commit is contained in:
David Dollar
2012-02-24 11:31:21 -05:00
parent 62c9d1db45
commit 12f825204b
2 changed files with 22 additions and 10 deletions
+6 -2
View File
@@ -213,9 +213,13 @@ private ######################################################################
def read_environment(filename)
return {} unless File.exists?(filename)
if line =~ /\A([A-Za-z_0-9]+)=(.*)\z/
hash[$1] = $2
File.read(filename).split("\n").inject({}) do |hash, line|
if line =~ /\A([A-Za-z_0-9]+)=(.*)\z/
key, val = [$1, $2]
case val
when /\A'(.*)'\z/ then hash[key] = $1
when /\A"(.*)"\z/ then hash[key] = $1.gsub(/\\(.)/, '\1')
else hash[key] = val
end
end
hash