diff --git a/Gemfile b/Gemfile index 3470ea20..525e4343 100644 --- a/Gemfile +++ b/Gemfile @@ -2,6 +2,8 @@ source "http://rubygems.org" gemspec +gem 'dotenv', :github => 'bkeepers/dotenv', :branch => '0.7' + platform :mingw do gem "win32console", "~> 1.3.0" end diff --git a/Gemfile.lock b/Gemfile.lock index 02cf254e..a14c4453 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,15 @@ +GIT + remote: git://github.com/bkeepers/dotenv.git + revision: bd139d3c2e627c4f5958542de50a1ae7038f0f8d + branch: 0.7 + specs: + dotenv (0.7.0) + PATH remote: . specs: foreman (0.62.0) + dotenv (>= 0.7) thor (>= 0.13.6) GEM @@ -52,6 +60,7 @@ PLATFORMS DEPENDENCIES aws-s3 + dotenv! fakefs (~> 0.3.2) foreman! posix-spawn (~> 0.3.6) diff --git a/foreman.gemspec b/foreman.gemspec index c258fc13..b49e14fa 100644 --- a/foreman.gemspec +++ b/foreman.gemspec @@ -18,6 +18,7 @@ Gem::Specification.new do |gem| gem.files << "man/foreman.1" gem.add_dependency 'thor', '>= 0.13.6' + gem.add_dependency 'dotenv', '>= 0.7' if ENV["PLATFORM"] == "java" gem.add_dependency "posix-spawn", "~> 0.3.6" diff --git a/lib/foreman/engine.rb b/lib/foreman/engine.rb index 7463e53c..f9e0a7eb 100644 --- a/lib/foreman/engine.rb +++ b/lib/foreman/engine.rb @@ -1,7 +1,7 @@ require "foreman" -require "foreman/env" require "foreman/process" require "foreman/procfile" +require "dotenv" require "tempfile" require "timeout" require "fileutils" @@ -172,9 +172,7 @@ def load_procfile(filename) # @param [String] filename A .env file to load into the environment # def load_env(filename) - Foreman::Env.new(filename).entries do |name, value| - @env[name] = value - end + @env.update Dotenv::Environment.new(filename) end # Send a signal to all processes started by this +Engine+ diff --git a/lib/foreman/env.rb b/lib/foreman/env.rb deleted file mode 100644 index 1b65514e..00000000 --- a/lib/foreman/env.rb +++ /dev/null @@ -1,29 +0,0 @@ -require "foreman" - -class Foreman::Env - - attr_reader :entries - - def initialize(filename) - @entries = File.read(filename).gsub("\r\n","\n").split("\n").inject({}) do |ax, line| - if line =~ /\A([A-Za-z_0-9]+)=(.*)\z/ - key = $1 - case val = $2 - # Remove single quotes - when /\A'(.*)'\z/ then ax[key] = $1 - # Remove double quotes and unescape string preserving newline characters - when /\A"(.*)"\z/ then ax[key] = $1.gsub('\n', "\n").gsub(/\\(.)/, '\1') - else ax[key] = val - end - end - ax - end - end - - def entries - @entries.each do |key, value| - yield key, value - end - end - -end