class Dotenv::Environment
Constants
- LINE
Public Class Methods
new(filename)
click to toggle source
# File lib/dotenv/environment.rb, line 21 def initialize(filename) @filename = filename load end
Public Instance Methods
apply()
click to toggle source
# File lib/dotenv/environment.rb, line 43 def apply each { |k,v| ENV[k] ||= v } end
load()
click to toggle source
# File lib/dotenv/environment.rb, line 26 def load read.each do |line| if match = line.match(LINE) key, value = match.captures value = value.strip.sub(/\A(['"])(.*)\1\z/, '\2') value = value.gsub('\n', "\n").gsub(/\(.)/, '\1') if $1 == '"' self[key] = value elsif line !~ /\A\s*(?:#.*)?\z/ # not comment or blank line raise FormatError, "Line #{line.inspect} doesn't match format" end end end
read()
click to toggle source
# File lib/dotenv/environment.rb, line 39 def read File.read(@filename).split("\n") end