Class: Dry::System::Settings::FileParser

Inherits:
Object
  • Object
show all
Defined in:
lib/dry/system/settings/file_parser.rb

Constant Summary collapse

LINE =
%r(
  \A
  \s*
  (?:export\s+)?    # optional export
  ([\w\.]+)         # key
  (?:\s*=\s*|:\s+?) # separator
  (                 # optional value begin
    '(?:\'|[^'])*'  #   single quoted value
    |               #   or
    "(?:\"|[^"])*"  #   double quoted value
    |               #   or
    [^#\n]+         #   unquoted value
  )?                # value end
  \s*
  (?:\#.*)?         # optional comment
  \z
)x

Instance Method Summary collapse

Instance Method Details

#call(file) ⇒ Object


25
26
27
28
29
30
31
# File 'lib/dry/system/settings/file_parser.rb', line 25

def call(file)
  File.readlines(file).each_with_object({}) do |line, hash|
    parse_line(line, hash)
  end
rescue Errno::ENOENT
  {}
end