21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
# File 'lib/unifig/env/parser.rb', line 21
def call(file_path)
content = File.read(file_path)
vars = {}
parser = StringScanner.new(content.strip)
until parser.eos?
parser.skip(WHITESPACE)
next if parser.skip(COMMENT)
parser.skip(EXPORT)
key = (parser, KEY, 'Missing env key on line %i')
(parser, ASSIGNMENT, 'Missing env var assignment on line %i')
quote = parser.scan(QUOTE)
value =
if quote
parser.scan(/.*?#{quote}/m).chop
else
parser.scan(SINGLE_LINE_VALUE)
end
(parser, TO_END_OF_LINE, 'Invalid env var value on line %i')
vars[key] = value
end
vars
end
|