Merge pull request #103 from csquared/load_env_from_irb
Load env from irb
This commit is contained in:
commit
6160246da0
3 files changed
+43
-2
No files matched your search
@@ -4,5 +4,10 @@ module Foreman
|
|||||||
|
|
||||||
class AppDoesNotExist < Exception; end
|
class AppDoesNotExist < Exception; end
|
||||||
|
|
||||||
|
# load contents of env_file into ENV
|
||||||
|
def self.load_env!(env_file = './.env')
|
||||||
|
require 'foreman/engine'
|
||||||
|
Foreman::Engine.load_env!(env_file)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
+16
-2
@@ -12,7 +12,6 @@ class Foreman::Engine
|
|||||||
|
|
||||||
attr_reader :procfile
|
attr_reader :procfile
|
||||||
attr_reader :directory
|
attr_reader :directory
|
||||||
attr_reader :environment
|
|
||||||
attr_reader :options
|
attr_reader :options
|
||||||
|
|
||||||
extend Term::ANSIColor
|
extend Term::ANSIColor
|
||||||
@@ -26,6 +25,11 @@ class Foreman::Engine
|
|||||||
@environment = read_environment_files(options[:env])
|
@environment = read_environment_files(options[:env])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.load_env!(env_file)
|
||||||
|
@environment = read_environment_files(env_file)
|
||||||
|
apply_environment!
|
||||||
|
end
|
||||||
|
|
||||||
def start
|
def start
|
||||||
proctitle "ruby: foreman master"
|
proctitle "ruby: foreman master"
|
||||||
termtitle "#{File.basename(@directory)} - foreman (#{processes.size} processes)"
|
termtitle "#{File.basename(@directory)} - foreman (#{processes.size} processes)"
|
||||||
@@ -73,7 +77,7 @@ private ######################################################################
|
|||||||
end
|
end
|
||||||
|
|
||||||
def fork_individual(process, num, port)
|
def fork_individual(process, num, port)
|
||||||
@environment.each { |k,v| ENV[k] = v }
|
apply_environment!
|
||||||
|
|
||||||
ENV["PORT"] = port.to_s
|
ENV["PORT"] = port.to_s
|
||||||
ENV["PS"] = "#{process.name}.#{num}"
|
ENV["PS"] = "#{process.name}.#{num}"
|
||||||
@@ -175,6 +179,9 @@ private ######################################################################
|
|||||||
@current_color >= COLORS.length ? "" : COLORS[@current_color]
|
@current_color >= COLORS.length ? "" : COLORS[@current_color]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
module Env
|
||||||
|
attr_reader :environment
|
||||||
|
|
||||||
def read_environment_files(filenames)
|
def read_environment_files(filenames)
|
||||||
environment = {}
|
environment = {}
|
||||||
|
|
||||||
@@ -198,4 +205,11 @@ private ######################################################################
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def apply_environment!
|
||||||
|
@environment.each { |k,v| ENV[k] = v }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
include Env
|
||||||
|
extend Env
|
||||||
end
|
end
|
||||||
@@ -8,4 +8,26 @@ describe Foreman do
|
|||||||
it { should be_a String }
|
it { should be_a String }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "::load_env!(env_file)" do
|
||||||
|
before do
|
||||||
|
FakeFS.activate!
|
||||||
|
end
|
||||||
|
|
||||||
|
after do
|
||||||
|
FakeFS.deactivate!
|
||||||
|
ENV['FOO'] = nil
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should load env_file into ENV" do
|
||||||
|
File.open("/tmp/env1", "w") { |f| f.puts("FOO=bar") }
|
||||||
|
Foreman.load_env!("/tmp/env1")
|
||||||
|
ENV['FOO'].should == 'bar'
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should assume env_file in ./.env" do
|
||||||
|
File.open("./.env", "w") { |f| f.puts("FOO=bar") }
|
||||||
|
Foreman.load_env!
|
||||||
|
ENV['FOO'].should == 'bar'
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
Reference in new issue
Block a user