Compare commits

..

2 Commits

Author SHA1 Message Date
David Dollar
ed44a11e21 0.23.0 2011-09-16 18:25:02 -04:00
David Dollar
5719f4fc72 allow multiple environment files to be specified 2011-09-16 18:24:38 -04:00
4 changed files with 29 additions and 12 deletions

View File

@@ -1,7 +1,7 @@
PATH
remote: .
specs:
foreman (0.22.0)
foreman (0.23.0)
term-ansicolor (~> 1.0.5)
thor (>= 0.13.6)

View File

@@ -22,7 +22,7 @@ class Foreman::Engine
@procfile = read_procfile(procfile)
@directory = File.expand_path(File.dirname(procfile))
@options = options
@environment = read_environment(options[:env])
@environment = read_environment_files(options[:env])
end
def processes
@@ -202,22 +202,29 @@ private ######################################################################
puts "!!! e.g. web: thin start"
end
def read_environment(filename)
error "No such file: #{filename}" if filename && !File.exists?(filename)
filename ||= ".env"
def read_environment_files(filenames)
environment = {}
if File.exists?(filename)
File.read(filename).split("\n").each do |line|
if line =~ /\A([A-Za-z_]+)=(.*)\z/
environment[$1] = $2
end
end
(filenames || "").split(",").map(&:strip).each do |filename|
error "No such file: #{filename}" unless File.exists?(filename)
environment.merge!(read_environment(filename))
end
environment.merge!(read_environment(".env")) unless filenames
environment
end
def read_environment(filename)
return {} unless File.exists?(filename)
File.read(filename).split("\n").inject({}) do |hash, line|
if line =~ /\A([A-Za-z_]+)=(.*)\z/
hash[$1] = $2
end
hash
end
end
def runner
File.expand_path("../../../bin/foreman-runner", __FILE__)
end

View File

@@ -1,5 +1,5 @@
module Foreman
VERSION = "0.22.0"
VERSION = "0.23.0"
end

View File

@@ -79,6 +79,16 @@ describe "Foreman::Engine" do
engine.execute("alpha")
end
it "should read more than one if specified" do
File.open("/tmp/env1", "w") { |f| f.puts("FOO=bar") }
File.open("/tmp/env2", "w") { |f| f.puts("BAZ=qux") }
engine = Foreman::Engine.new("Procfile", :env => "/tmp/env1,/tmp/env2")
stub(engine).info
mock(engine).watch_for_termination
engine.environment.should == { "FOO"=>"bar", "BAZ"=>"qux" }
engine.execute("alpha")
end
it "should fail if specified and doesnt exist" do
mock.instance_of(Foreman::Engine).error("No such file: /tmp/env")
engine = Foreman::Engine.new("Procfile", :env => "/tmp/env")