Module: Slidict::Env

Defined in:
lib/slidict/env.rb

Overview

Loads KEY=VALUE pairs from a .env file (if present) into ENV, so SLIDICT_LLM_BASE_URL, SLIDICT_FRAMEWORK, etc. can be set once per project instead of on every invocation. Only keys not already present in ENV are populated -- a real environment variable always wins over .env, and a CLI flag (read afterwards, in Cli::App#parse) wins over both. See slidict init for generating a starter file.

Constant Summary collapse

LINE =
/\A(?:export\s+)?([A-Za-z_][A-Za-z0-9_]*)=(.*)\z/

Class Method Summary collapse

Class Method Details

.load!(path = ".env", env = ENV) ⇒ Object



13
14
15
16
17
18
19
20
# File 'lib/slidict/env.rb', line 13

def self.load!(path = ".env", env = ENV)
  return unless File.exist?(path)

  File.foreach(path) do |line|
    key, value = parse_line(line)
    env[key] = value if key && !env.key?(key)
  end
end