Module: Philiprehberger::EnvDiff::Parser

Defined in:
lib/philiprehberger/env_diff/parser.rb

Overview

Parses .env file content into a key-value hash.

Class Method Summary collapse

Class Method Details

.parse(content) ⇒ Hash{String => String}

Parse a string of env file content into a hash.

Parameters:

  • content (String)

    the raw .env file content

Returns:

  • (Hash{String => String})

    parsed key-value pairs



11
12
13
14
15
16
17
18
# File 'lib/philiprehberger/env_diff/parser.rb', line 11

def self.parse(content)
  result = {}
  content.each_line do |line|
    key, value = parse_line(line.strip)
    result[key] = value if key
  end
  result
end

.parse_file(path:) ⇒ Hash{String => String}

Read a file and parse its content.

Parameters:

  • path (String)

    path to the .env file

Returns:

  • (Hash{String => String})

    parsed key-value pairs

Raises:

  • (Errno::ENOENT)

    if the file does not exist



25
26
27
# File 'lib/philiprehberger/env_diff/parser.rb', line 25

def self.parse_file(path:)
  parse(File.read(path))
end