module Dotenv
  class Environment < Hash
    def initialize(filename)
      @filename = filename
      load if File.exists? @filename
    end

    def load
      read.each do |line|
        self[$1] = $2 || $3 if line =~ /\A(\w+)(?:=|: ?)(?:['"]([^'"]*)['"]|([^'"]*))\z/
      end
    end

    def read
      File.read(@filename).split("\n")
    end

    def apply
      each { |k,v| ENV[k] ||= v }
    end
  end
end

module Dotenv
  class Environment < Hash
    def initialize(filename)
      @filename = filename
      load if File.exists? @filename
    end

    def load
      read.each do |line|
        self[$1] = $2 || $3 if line =~ /\A(?:export\s+)?(\w+)(?:=|: ?)(?:['"]([^'"]*)['"]|([^'"]*))\z/i
      end
    end

    def read
      File.read(@filename).split("\n")
    end

    def apply
      each { |k,v| ENV[k] ||= v }
    end
  end
end

Allow for env variables set with 'export' keyword
Allow for env variables set with 'export' keyword
