Replace Foreman::Env with dotenv
This commit is contained in:
2
Gemfile
2
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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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 @@ class Foreman::Engine
|
||||
# @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+
|
||||
|
||||
@@ -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
|
||||
Reference in New Issue
Block a user