Module: Pray::Dotenv
- Defined in:
- lib/pray/dotenv.rb
Class Method Summary collapse
- .load_dotenv_variables(project_root_hint) ⇒ Object
- .parse_dotenv_text(text) ⇒ Object
- .parse_dotenv_value(value) ⇒ Object
Class Method Details
.load_dotenv_variables(project_root_hint) ⇒ Object
7 8 9 10 11 12 13 14 15 |
# File 'lib/pray/dotenv.rb', line 7 def load_dotenv_variables(project_root_hint) path = File.join(project_root_hint, ".env") return {} unless File.file?(path) text = File.read(path) parse_dotenv_text(text) rescue {} end |
.parse_dotenv_text(text) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/pray/dotenv.rb', line 17 def parse_dotenv_text(text) variables = {} text.each_line do |line| trimmed = line.strip next if trimmed.empty? || trimmed.start_with?("#") assignment = trimmed.delete_prefix("export ").strip key, value = assignment.split("=", 2) next unless value key = key.strip next if key.empty? next unless key.start_with?("PRAY_") variables[key] = parse_dotenv_value(value.strip) end variables end |
.parse_dotenv_value(value) ⇒ Object
36 37 38 39 40 41 42 43 44 |
# File 'lib/pray/dotenv.rb', line 36 def parse_dotenv_value(value) if value.length >= 2 quote = value[0] if (quote == '"' || quote == "'") && value[-1] == quote return value[1...-1] end end value end |