Class: DocktorRails::Dotenv

Inherits:
Object
  • Object
show all
Defined in:
lib/docktor_rails/dotenv.rb

Class Method Summary collapse

Class Method Details

.parse(content) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/docktor_rails/dotenv.rb', line 11

def self.parse(content)
  env = {}
  content.each_line do |line|
    line = line.strip
    next if line.empty? || line.start_with?("#")

    key, value = line.split("=", 2)
    next if key.nil? || key.empty?

    value = "" if value.nil?
    value = value.strip
    value = value[1..-2] if (value.start_with?("\"") && value.end_with?("\"")) || (value.start_with?("'") && value.end_with?("'"))
    env[key] = value
  end
  env
end

.parse_file(path) ⇒ Object



5
6
7
8
9
# File 'lib/docktor_rails/dotenv.rb', line 5

def self.parse_file(path)
  return {} unless File.file?(path)

  parse(File.read(path))
end